{
  "id": "python/unittest-teardown-exception-masked",
  "signature": "ERROR: test_foo (tests.test_x.TestCase.test_foo)\n----------------------------------------------------------------------\nTraceback (most recent call last):\n  File \"...\", line N, in tearDown\n    self.conn.close()\nAttributeError: 'NoneType' object has no attribute 'close'",
  "signature_zh": "ERROR: test_foo (tests.test_x.TestCase.test_foo)\n----------------------------------------------------------------------\nTraceback (most recent call last):\n  File \"...\", 第 N 行, 在 tearDown 中\n    self.conn.close()\nAttributeError: 'NoneType' 对象没有属性 'close'",
  "regex": "ERROR:\\ test_foo\\ \\(tests\\.test_x\\.TestCase\\.test_foo\\)\\\n\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\\nTraceback\\ \\(most\\ recent\\ call\\ last\\):\\\n\\ \\ File\\ \"\\.\\.\\.\",\\ line\\ N,\\ in\\ tearDown\\\n\\ \\ \\ \\ self\\.conn\\.close\\(\\)\\\nAttributeError:\\ 'NoneType'\\ object\\ has\\ no\\ attribute\\ 'close'",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "tearDown runs even when setUp failed, so resources are None; the teardown exception replaces the original test error, obscuring the real failure.",
  "root_cause_type": "generic",
  "root_cause_zh": "即使 setUp 失败，tearDown 也会运行，因此资源为 None；teardown 异常替换了原始测试错误，掩盖了真正的失败。",
  "versions": [
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Silences real teardown errors and leaks resources, causing cascading failures in later tests.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Resources (DB connections, temp files) leak between tests, causing flakiness and cross-test pollution.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Symptom-level fix; the underlying setUp failure still hides behind the teardown error path.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "def setUp(self):\n    self.conn = create_conn()\n    self.addCleanup(self.conn.close)\n\n# If create_conn raises, addCleanup is never registered, so tearDown does nothing",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "def tearDown(self):\n    conn = getattr(self, 'conn', None)\n    if conn is not None:\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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-11-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}