{
  "id": "python/pytest-fixture-teardown-error",
  "signature": "E   RuntimeError: database connection still open after teardown\nE   ERROR at teardown of test_create_user",
  "signature_zh": "E   RuntimeError: teardown 后数据库连接仍未关闭\nE   test_create_user 的 teardown 出错",
  "regex": "E\\ \\ \\ RuntimeError:\\ database\\ connection\\ still\\ open\\ after\\ teardown\\\nE\\ \\ \\ ERROR\\ at\\ teardown\\ of\\ test_create_user",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A fixture's teardown code raised an exception, often because the resource was already closed or the test left it in an inconsistent state.",
  "root_cause_type": "generic",
  "root_cause_zh": "fixture 的 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": "Leaks connections and causes cascading failures in later tests.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Hides real resource leaks and makes debugging harder.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Guard teardown with a check:\n@pytest.fixture\ndef db():\n    conn = connect()\n    yield conn\n    if not conn.closed:\n        conn.close()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Use `addfinalizer` for ordered cleanup:\n@pytest.fixture\ndef resource(request):\n    r = acquire()\n    request.addfinalizer(r.release)\n    return 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.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-08",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}