{
  "id": "python/pytest-asyncio-no-running-loop",
  "signature": "RuntimeError: no running event loop\n  File \".../pytest_asyncio/plugin.py\", line ..., in pytest_pyfunc_call\n    result = loop.run_until_complete(...)",
  "signature_zh": "RuntimeError: 没有正在运行的事件循环\n  文件 \".../pytest_asyncio/plugin.py\"，行 ...，在 pytest_pyfunc_call 中\n    result = loop.run_until_complete(...)",
  "regex": "RuntimeError:\\ no\\ running\\ event\\ loop\\\n\\ \\ File\\ \"\\.\\.\\./pytest_asyncio/plugin\\.py\",\\ line\\ \\.\\.\\.,\\ in\\ pytest_pyfunc_call\\\n\\ \\ \\ \\ result\\ =\\ loop\\.run_until_complete\\(\\.\\.\\.\\)",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "An async test was collected without being marked with @pytest.mark.asyncio, or pytest-asyncio mode is set to 'strict' (default) and the marker is missing. The plugin refuses to run the coroutine.",
  "root_cause_type": "generic",
  "root_cause_zh": "异步测试被收集但未标记 @pytest.mark.asyncio，或者 pytest-asyncio 模式设置为 'strict'（默认）且缺少标记。插件拒绝运行该协程。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "pytest-asyncio already manages the loop; calling asyncio.run() inside a coroutine raises 'asyncio.run() cannot be called from a running event loop'.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If pytest reads pyproject.toml instead, the config is ignored and strict mode persists.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "import pytest\n\n@pytest.mark.asyncio\nasync def test_fetch():\n    result = await fetch()\n    assert result == 42",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "# pyproject.toml\n[tool.pytest.ini_options]\nasyncio_mode = \"auto\"\n\n# or pytest.ini\n# [pytest]\n# asyncio_mode = auto",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}