{
  "id": "python/pytest-fixture-teardown-error-masked",
  "signature": "ERROR at teardown of test_create_user\nE   RuntimeError: database connection already closed\n\nERROR at setup of test_create_user\nE   RuntimeError: database connection already closed",
  "signature_zh": "ERROR 在 test_create_user 的 teardown 处\nE   RuntimeError: 数据库连接已关闭\n\nERROR 在 test_create_user 的 setup 处\nE   RuntimeError: 数据库连接已关闭",
  "regex": "ERROR\\ at\\ teardown\\ of\\ test_create_user\\\nE\\ \\ \\ RuntimeError:\\ database\\ connection\\ already\\ closed\\\n\\\nERROR\\ at\\ setup\\ of\\ test_create_user\\\nE\\ \\ \\ RuntimeError:\\ database\\ connection\\ already\\ closed",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A session- or module-scoped fixture closed a shared resource in its teardown, but subsequent tests in the same scope still tried to use it, producing errors at both teardown and the next setup.",
  "root_cause_type": "generic",
  "root_cause_zh": "会话或模块作用域的 fixture 在其 teardown 中关闭了共享资源，但同一作用域中的后续测试仍试图使用它，导致 teardown 和下一次 setup 都报错。",
  "versions": [
    {
      "version": "6.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "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": "That flag affects collection errors, not fixture teardown errors; tests still error out.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Swallows the error but leaves the resource closed, so subsequent tests still fail at setup.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "@pytest.fixture\ndef db():\n    conn = connect()\n    yield conn\n    conn.close()\n# each test gets a fresh connection",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "@pytest.fixture(scope='session')\ndef engine():\n    eng = create_engine(...)\n    yield eng\n    eng.dispose()\n\n@pytest.fixture\ndef db(engine):\n    conn = engine.connect()\n    trans = conn.begin()\n    yield conn\n    trans.rollback()\n    conn.close()",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-11",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}