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

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  1. 98% 成功率
    pip install pytest-asyncio
    # pytest.ini
    # [pytest]
    # asyncio_mode = auto
  2. 85% 成功率
    # pytest.ini
    # [pytest]
    # markers =
    #   asyncio: mark test as async
    # filterwarnings =
    #   error::pytest.PytestUnknownMarkWarning

无效尝试

常见但无效的做法:

  1. 95% 失败

    The coroutine still is not awaited; the test silently passes without executing assertions.

  2. 90% 失败

    Duplicate marks do nothing; the plugin is still missing.