python
install_error
ai_generated
true
async def functions are not natively supported. You need to install a suitable plugin for your async framework, for example: - anyio - pytest-asyncio
ID: python/pytest-asyncio-not-installed
80%Fix Rate
90%Confidence
0Evidence
2024-02-08First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
Pytest cannot run `async def` test functions without an async plugin. The test is collected but pytest refuses to execute it because the event loop is not managed.
generic中文
在没有异步插件的情况下,pytest 无法运行 `async def` 测试函数。测试会被收集,但 pytest 拒绝执行,因为没有管理事件循环。
Workarounds
-
98% success
Install the plugin and enable auto mode: pip install pytest-asyncio # pytest.ini [pytest] asyncio_mode = auto
-
90% success
Use anyio instead: pip install anyio # test file import pytest @pytest.mark.anyio async def test_thing(): ...
Dead Ends
Common approaches that don't work:
-
90% fail
The test function itself is still async, so pytest still rejects it during collection.
-
95% fail
The setting is only read by pytest-asyncio; without the plugin installed the option is ignored and the error persists.