{
  "id": "python/pytest-fixture-yield-teardown-error",
  "signature": "ERROR at teardown of test_x\nRuntimeError: generator didn't stop after throw()",
  "signature_zh": "test_x 拆卸时出错\nRuntimeError：throw() 之后生成器未停止",
  "regex": "ERROR\\ at\\ teardown\\ of\\ test_x\\\nRuntimeError:\\ generator\\ didn't\\ stop\\ after\\ throw\\(\\)",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A yield fixture's teardown raised an exception that was swallowed, or the generator caught GeneratorExit and continued yielding.",
  "root_cause_type": "generic",
  "root_cause_zh": "yield fixture 的拆卸引发了被吞掉的异常，或生成器捕获了 GeneratorExit 并继续 yield。",
  "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": "Hides the original error and can leak resources.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Loses teardown entirely; resources leak.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Unrelated to generator teardown.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "@pytest.fixture\ndef resource():\n    r = acquire()\n    try:\n        yield r\n    finally:\n        r.close()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "import contextlib\n\n@contextlib.contextmanager\ndef resource_cm():\n    r = acquire()\n    try:\n        yield r\n    finally:\n        r.close()\n\n@pytest.fixture\ndef resource():\n    with resource_cm() as r:\n        yield r",
      "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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-08-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}