{
  "id": "python/pytest-asyncio-no-event-loop",
  "signature": "RuntimeError: no running event loop\nasync def functions are not natively supported. You need to install a suitable plugin for your async framework, for example: - anyio - pytest-asyncio",
  "signature_zh": "RuntimeError: 没有正在运行的事件循环\nasync def 函数未被原生支持。你需要为异步框架安装合适的插件，例如：- anyio - pytest-asyncio",
  "regex": "RuntimeError:\\ no\\ running\\ event\\ loop\\\nasync\\ def\\ functions\\ are\\ not\\ natively\\ supported\\.\\ You\\ need\\ to\\ install\\ a\\ suitable\\ plugin\\ for\\ your\\ async\\ framework,\\ for\\ example:\\ \\-\\ anyio\\ \\-\\ pytest\\-asyncio",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "pytest does not run async test functions without a plugin; without pytest-asyncio (or anyio) configured, coroutine tests are skipped or raise this error.",
  "root_cause_type": "generic",
  "root_cause_zh": "pytest 在没有插件的情况下不会运行异步测试函数；未配置 pytest-asyncio（或 anyio）时，协程测试被跳过或抛出此错误。",
  "versions": [
    {
      "version": "7.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Works for trivial tests but breaks fixtures, event-loop-scoped resources, and any test that relies on pytest's async fixtures.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The marker is unknown to pytest and triggers a PytestUnknownMarkWarning; the coroutine is still not awaited.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The ini option is only recognized by pytest-asyncio; without the plugin it has no effect.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "pip install pytest-asyncio\n\n# pytest.ini\n[pytest]\nasyncio_mode = auto\n\n# tests\nimport pytest\n\n@pytest.mark.asyncio\nasync def test_fetch():\n    assert await fetch()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "pip install anyio\n\n# pytest.ini\n[pytest]\naddopts = --anyio-mode=auto\n\n# tests\nimport pytest\n\n@pytest.mark.anyio\nasync def test_fetch():\n    assert await fetch()",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-19",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}