{
  "id": "python/pytest-fixture-yield-without-finally",
  "signature": "RuntimeError: generator didn't stop after throw()",
  "signature_zh": "运行时错误：生成器在 throw() 后没有停止",
  "regex": "RuntimeError:\\ generator\\ didn't\\ stop\\ after\\ throw\\(\\)",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "在 fixture 的 yield 之后没有正确处理异常，导致 teardown 代码未执行或生成器未正确关闭。",
  "root_cause_type": "generic",
  "root_cause_zh": "在 fixture 的 yield 之后没有正确处理异常，导致 teardown 代码未执行或生成器未正确关闭。",
  "versions": [
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "yield 后直接写清理代码",
      "why_fails": "尝试在 yield 后直接写清理代码，但异常发生时清理代码不执行",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "在 finally 中再次 yield",
      "why_fails": "尝试使用 try/finally 但 finally 中又 yield 导致错误",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "确保 yield 后没有异常中断",
      "success_rate": 0.9,
      "how": "@pytest.fixture\ndef my_fixture():\n    setup()\n    yield resource\n    teardown()",
      "condition": "",
      "sources": []
    },
    {
      "action": "使用 try/finally 确保清理",
      "success_rate": 0.95,
      "how": "@pytest.fixture\ndef my_fixture():\n    try:\n        yield resource\n    finally:\n        teardown()",
      "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.81,
  "fix_success_rate": 0.8,
  "resolvable": "partial",
  "first_seen": "2024-09-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}