python
install_error
ai_generated
true
PytestUnknownMarkWarning: 未知的 pytest.mark.asyncio - 是否拼写错误?可以注册自定义标记以避免此警告 - 详情见 https://docs.pytest.org/en/stable/how-to/mark.html
PytestUnknownMarkWarning: Unknown pytest.mark.asyncio - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
ID: python/pytest-mark-async-without-plugin
80%修复率
87%置信度
0证据数
2024-06-18首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 0.21 | active | — | — | — |
| 0.23 | active | — | — | — |
根因分析
异步测试标记了 @pytest.mark.asyncio,但未安装或未启用 pytest-asyncio,导致协程从未被 await,测试未执行却通过。
English
The async test is marked with @pytest.mark.asyncio but pytest-asyncio is not installed or not enabled, so the coroutine is never awaited and the test passes without running.
解决方案
-
98% 成功率
pip install pytest-asyncio # pytest.ini # [pytest] # asyncio_mode = auto
-
85% 成功率
# pytest.ini # [pytest] # markers = # asyncio: mark test as async # filterwarnings = # error::pytest.PytestUnknownMarkWarning
无效尝试
常见但无效的做法:
-
95% 失败
The coroutine still is not awaited; the test silently passes without executing assertions.
-
90% 失败
Duplicate marks do nothing; the plugin is still missing.