python install_error ai_generated true

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2024-06-18First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
0.21 active — — —
0.23 active — — —

Root Cause

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

中文

异步测试标记了 @pytest.mark.asyncio,但未安装或未启用 pytest-asyncio,导致协程从未被 await,测试未执行却通过。

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 95% fail

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

  2. 90% fail

    Duplicate marks do nothing; the plugin is still missing.