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

ID: python/pytest-asyncio-no-mark

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
0.21 active — — —
0.23 active — — —
0.24 active — — —

Root Cause

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.

generic

中文

异步测试函数被收集时缺少 asyncio 标记,或 pytest-asyncio 处于 strict 模式。自 0.21 起默认 strict 模式下,每个异步测试都必须用 @pytest.mark.asyncio 装饰。

Workarounds

  1. 95% success
    Add to pytest.ini:
      [pytest]
      asyncio_mode = auto
    Or decorate each test:
      import pytest
      @pytest.mark.asyncio
      async def test_foo(): ...
  2. 85% success
    Install and use anyio instead:
      pip install anyio
      @pytest.mark.anyio
      async def test_foo(): ...

Dead Ends

Common approaches that don't work:

  1. 90% fail

    pytest still sees an async def and refuses to run it; the wrapper never executes.

  2. 85% fail

    The ini option is ignored if the plugin isn't installed; error persists.