You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"The test […] is not an async function" when asyncio marker is added via pytest_collection_modifyitems() #810
========================================================= test session starts =========================================================
platform linux -- Python 3.11.8, pytest-8.1.1, pluggy-1.4.0
rootdir: /tmp/reproplugins: asyncio-0.23.6asyncio: mode=Mode.STRICT
collected 1 item
test_foo.py s [100%]
========================================================== warnings summary ===========================================================
test_foo.py::test_foo
test_foo.py:5: PytestWarning: The test <Function test_foo> is marked with '@pytest.mark.asyncio' but it is not an async function. Please remove the asyncio mark. If the test is not marked explicitly, check for global marks applied via 'pytestmark'.
asyncdeftest_foo():
test_foo.py::test_foo
/tmp/repro/.venv/lib/python3.11/site-packages/_pytest/python.py:184: PytestUnhandledCoroutineWarning: async def functions are not natively supported and have been skipped.
You need to install a suitable plugin for your async framework, for example:
- anyio
- pytest-asyncio
- pytest-tornasync
- pytest-trio
- pytest-twisted
warnings.warn(PytestUnhandledCoroutineWarning(msg.format(nodeid)))
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================== 1 skipped, 2 warnings in 0.01s ====================================================
With pytest-asyncio-0.21.1, the test is correctly run as marked.
As of the 1.4 alphas, I am not sure if there is a way for pytest-asyncio to support late markers safely. The plugin uses the presence of the asyncio marker to determine what items to parametrize and how to parametrize them. By the time pytest_collection_modifyitems is run, the items have been parametrized and pytest, from what I can tell, does not support late parametrization (at least, not without implementing a hack via its internals).
Applying the markers via pytest_pycollect_makeitem before pytest-asyncio's collection-time conversion happens should work and would mean that items participate in parametrization as intended. Does that fix your use case?
Activity
mgorny commentedon Apr 16, 2024
Also affects PyZMQ.
seifertm commentedon May 26, 2025
Still reproducible in pytest-asyncio v1.0.0a1.
JiwaniZakir commentedon Mar 16, 2026
I think I see what's going on here. Going to put together a fix.
test: add regression test for issue pytest-dev#810
tjkuson commentedon May 8, 2026
As of the 1.4 alphas, I am not sure if there is a way for pytest-asyncio to support late markers safely. The plugin uses the presence of the
asynciomarker to determine what items to parametrize and how to parametrize them. By the timepytest_collection_modifyitemsis run, the items have been parametrized and pytest, from what I can tell, does not support late parametrization (at least, not without implementing a hack via its internals).Applying the markers via
pytest_pycollect_makeitembefore pytest-asyncio's collection-time conversion happens should work and would mean that items participate in parametrization as intended. Does that fix your use case?