{
  "id": "python/pytest-fixture-finalizer-error-masked",
  "signature": "ERROR at teardown of test_create_user\n  File \".../conftest.py\", line 42, in db\n    conn.close()\npsycopg2.OperationalError: server closed the connection unexpectedly",
  "signature_zh": "test_create_user 的 teardown 出错\n  File \".../conftest.py\", 行 42, 在 db\n    conn.close()\npsycopg2.OperationalError: 服务器意外关闭了连接",
  "regex": "ERROR\\ at\\ teardown\\ of\\ test_create_user\\\n\\ \\ File\\ \"\\.\\.\\./conftest\\.py\",\\ line\\ 42,\\ in\\ db\\\n\\ \\ \\ \\ conn\\.close\\(\\)\\\npsycopg2\\.OperationalError:\\ server\\ closed\\ the\\ connection\\ unexpectedly",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A fixture's teardown code (after yield) raises because the resource it cleans up (DB connection, temp server) was already closed by the test or by an earlier fixture. pytest reports this as a teardown ERROR, which can mask the original test result.",
  "root_cause_type": "generic",
  "root_cause_zh": "fixture 的清理代码（yield 之后）抛出异常，因为它清理的资源（数据库连接、临时服务器）已被测试或更早的 fixture 关闭。pytest 将其报告为 teardown ERROR，可能掩盖原始测试结果。",
  "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 teardown failures but leaves leaked connections and masks real resource bugs.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Changes lifecycle and can cause cross-test contamination; the teardown error may still occur.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "@pytest.fixture\ndef db():\n    conn = connect()\n    try:\n        yield conn\n    finally:\n        if not conn.closed:\n            conn.close()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "def test_query(db):\n    with db.cursor() as cur:\n        cur.execute('SELECT 1')\n    # do not call db.close() here; the fixture owns it",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-10-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}