{
  "id": "python/pytest-session-fixture-finalizer-error",
  "signature": "ERROR at teardown of test_foo\nRuntimeError: generator didn't stop after throw()",
  "signature_zh": "test_foo 拆卸时出错\nRuntimeError: 在 throw() 之后生成器没有停止",
  "regex": "ERROR\\ at\\ teardown\\ of\\ test_foo\\\nRuntimeError:\\ generator\\ didn't\\ stop\\ after\\ throw\\(\\)",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A yield-based fixture raised an exception inside its teardown after the yield, and the generator did not catch it, so pytest's finalizer machinery reports the generator as still running.",
  "root_cause_type": "generic",
  "root_cause_zh": "基于 yield 的 fixture 在 yield 之后的 teardown 中引发异常，生成器未捕获，pytest 的 finalizer 机制报告生成器仍在运行。",
  "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": "The error occurs during fixture teardown, outside the test body, so the test's try/except never sees it.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Loses teardown entirely; resources are never released and the error is replaced by a leak.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "@pytest.fixture\ndef client():\n    c = connect()\n    try:\n        yield c\n    finally:\n        try:\n            c.close()\n        except Exception as e:\n            log.warning('close failed: %s', e)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "@pytest.fixture\ndef client(request):\n    c = connect()\n    request.addfinalizer(c.close)\n    return c",
      "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.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-10-08",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}