python
config_error
ai_generated
true
async def 函数不被原生支持。 你需要为异步框架安装合适的插件,例如: - anyio - pytest-asyncio - pytest-tornasync - pytest-trio - pytest-twisted
async def functions are not natively supported. You need to install a suitable plugin for your async framework, for example: - anyio - pytest-asyncio - pytest-tornasync - pytest-trio - pytest-twisted
ID: python/pytest-asyncio-no-plugin
80%修复率
87%置信度
0证据数
2024-05-08首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
pytest 不原生支持运行 async 测试函数。未安装 pytest-asyncio(或其他异步插件)且未配置 asyncio_mode 时,异步测试会报此错。
English
pytest does not natively run async test functions. Without pytest-asyncio (or another async plugin) and the correct asyncio_mode configuration, async tests are skipped/failed with this message.
解决方案
-
95% 成功率
pip install pytest-asyncio, then add to pyproject.toml or pytest.ini: [tool.pytest.ini_options] asyncio_mode = "auto" and mark tests with @pytest.mark.asyncio (or rely on auto mode).
-
85% 成功率
Alternatively use anyio: `pip install anyio` and decorate with `@pytest.mark.anyio`.
无效尝试
常见但无效的做法:
-
70% 失败
Runs at import time, not collection time, and breaks fixtures/event loop reuse.
-
75% 失败
The marker is unknown without the plugin; test still fails with the same message.