{
  "id": "python/pytest-fixture-finalizer-exception-masked",
  "signature": "ERROR at teardown of test_x\nRuntimeError: generator didn't stop after throw()\n# or: ERROR: test_x - Exception: teardown error swallowed",
  "signature_zh": "test_x 的 teardown 出错\nRuntimeError: generator didn't stop after throw()\n# 或: ERROR: test_x - Exception: teardown error swallowed",
  "regex": "ERROR\\ at\\ teardown\\ of\\ test_x\\\nRuntimeError:\\ generator\\ didn't\\ stop\\ after\\ throw\\(\\)\\\n\\#\\ or:\\ ERROR:\\ test_x\\ \\-\\ Exception:\\ teardown\\ error\\ swallowed",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A yield fixture's teardown raises an exception that masks the original test failure, or the generator is re-entered after yielding, causing pytest to report a teardown error.",
  "root_cause_type": "generic",
  "root_cause_zh": "yield fixture 的 teardown 抛出异常，掩盖了原始测试失败，或生成器在 yield 后被重新进入，导致 pytest 报告 teardown 错误。",
  "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": "Swallows real cleanup errors; resources may remain locked and subsequent tests fail.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Delays teardown to the end of the run but does not prevent the exception from masking failures.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "@pytest.fixture\ndef resource(request):\n    r = acquire()\n    request.addfinalizer(r.close)\n    return r",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "@pytest.fixture\ndef resource():\n    r = acquire()\n    yield r\n    try:\n        r.close()\n    except Exception:\n        import logging\n        logging.exception('teardown failed')\n        raise",
      "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": "partial",
  "first_seen": "2024-12-06",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}