python config_error ai_generated true

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

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7.x active — — —
8.x active — — —

Root Cause

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.

generic

中文

pytest 不原生支持运行 async 测试函数。未安装 pytest-asyncio(或其他异步插件)且未配置 asyncio_mode 时,异步测试会报此错。

Workarounds

  1. 95% success
    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).
  2. 85% success
    Alternatively use anyio: `pip install anyio` and decorate with `@pytest.mark.anyio`.

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Runs at import time, not collection time, and breaks fixtures/event loop reuse.

  2. 75% fail

    The marker is unknown without the plugin; test still fails with the same message.