python
config_error
ai_generated
true
async def 函数不被原生支持。 你需要为异步框架安装合适的插件,例如: - anyio - pytest-asyncio
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-no-mark
80%修复率
89%置信度
0证据数
2024-05-02首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 0.21 | active | — | — | — |
| 0.23 | active | — | — | — |
| 0.24 | active | — | — | — |
根因分析
异步测试函数被收集时缺少 asyncio 标记,或 pytest-asyncio 处于 strict 模式。自 0.21 起默认 strict 模式下,每个异步测试都必须用 @pytest.mark.asyncio 装饰。
English
An async test function was collected without an asyncio marker or without pytest-asyncio in strict mode. In strict mode (default since 0.21), every async test must be decorated with @pytest.mark.asyncio.
解决方案
-
95% 成功率
Add to pytest.ini: [pytest] asyncio_mode = auto Or decorate each test: import pytest @pytest.mark.asyncio async def test_foo(): ...
-
85% 成功率
Install and use anyio instead: pip install anyio @pytest.mark.anyio async def test_foo(): ...
无效尝试
常见但无效的做法:
-
90% 失败
pytest still sees an async def and refuses to run it; the wrapper never executes.
-
85% 失败
The ini option is ignored if the plugin isn't installed; error persists.