diff --git a/pytest_asyncio/plugin.py b/pytest_asyncio/plugin.py index 1ecfbe49..c31683ab 100644 --- a/pytest_asyncio/plugin.py +++ b/pytest_asyncio/plugin.py @@ -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) diff --git a/tests/modes/test_auto_mode.py b/tests/modes/test_auto_mode.py index 157ffded..fc4d2df0 100644 --- a/tests/modes/test_auto_mode.py +++ b/tests/modes/test_auto_mode.py @@ -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)