Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = obj.__func__
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)