Skip to content

Commit f0b6709

Browse files
committed
Fix asyncio auto mode not marking static methods.
1 parent 34436cd commit f0b6709

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

pytest_asyncio/plugin.py

+3
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ def pytest_pycollect_makeitem(
320320
if not collector.funcnamefilter(name):
321321
return None
322322
_preprocess_async_fixtures(collector.config, _HOLDER)
323+
if isinstance(obj, staticmethod):
324+
# staticmethods need to be unwrapped.
325+
obj = getattr(obj, "__func__", False)
323326
if (
324327
_is_coroutine(obj)
325328
or _is_hypothesis_test(obj)

tests/modes/test_auto_mode.py

+50
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,53 @@ async def test_a(self, fixture_a):
8787
)
8888
result = testdir.runpytest("--asyncio-mode=auto")
8989
result.assert_outcomes(passed=1)
90+
91+
92+
def test_auto_mode_static_method(testdir):
93+
testdir.makepyfile(
94+
dedent(
95+
"""\
96+
import asyncio
97+
98+
pytest_plugins = 'pytest_asyncio'
99+
100+
101+
class TestA:
102+
103+
@staticmethod
104+
async def test_a():
105+
await asyncio.sleep(0)
106+
"""
107+
)
108+
)
109+
result = testdir.runpytest("--asyncio-mode=auto")
110+
result.assert_outcomes(passed=1)
111+
112+
113+
def test_auto_mode_static_method_fixture(testdir):
114+
testdir.makepyfile(
115+
dedent(
116+
"""\
117+
import asyncio
118+
import pytest
119+
120+
pytest_plugins = 'pytest_asyncio'
121+
122+
123+
class TestA:
124+
125+
@staticmethod
126+
@pytest.fixture
127+
async def fixture_a():
128+
await asyncio.sleep(0)
129+
return 1
130+
131+
@staticmethod
132+
async def test_a(fixture_a):
133+
await asyncio.sleep(0)
134+
assert fixture_a == 1
135+
"""
136+
)
137+
)
138+
result = testdir.runpytest("--asyncio-mode=auto")
139+
result.assert_outcomes(passed=1)

0 commit comments

Comments
 (0)