Skip to content

Commit

Permalink
Fix asyncio auto mode not marking static methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriek committed Feb 17, 2022
1 parent 34436cd commit f0b6709
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ def pytest_pycollect_makeitem(
if not collector.funcnamefilter(name):
return None
_preprocess_async_fixtures(collector.config, _HOLDER)
if isinstance(obj, staticmethod):
# staticmethods need to be unwrapped.
obj = getattr(obj, "__func__", False)
if (
_is_coroutine(obj)
or _is_hypothesis_test(obj)
Expand Down
50 changes: 50 additions & 0 deletions tests/modes/test_auto_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,53 @@ async def test_a(self, fixture_a):
)
result = testdir.runpytest("--asyncio-mode=auto")
result.assert_outcomes(passed=1)


def test_auto_mode_static_method(testdir):
testdir.makepyfile(
dedent(
"""\
import asyncio
pytest_plugins = 'pytest_asyncio'
class TestA:
@staticmethod
async def test_a():
await asyncio.sleep(0)
"""
)
)
result = testdir.runpytest("--asyncio-mode=auto")
result.assert_outcomes(passed=1)


def test_auto_mode_static_method_fixture(testdir):
testdir.makepyfile(
dedent(
"""\
import asyncio
import pytest
pytest_plugins = 'pytest_asyncio'
class TestA:
@staticmethod
@pytest.fixture
async def fixture_a():
await asyncio.sleep(0)
return 1
@staticmethod
async def test_a(fixture_a):
await asyncio.sleep(0)
assert fixture_a == 1
"""
)
)
result = testdir.runpytest("--asyncio-mode=auto")
result.assert_outcomes(passed=1)

0 comments on commit f0b6709

Please sign in to comment.