{
  "id": "python/unittest-teardown-exception-masks-test",
  "signature": "ERROR: tearDown (tests.test_foo.TestFoo) ...\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: tearDown (tests.test_foo.TestFoo) ...\nTraceback (最近一次调用最后):\n  File \"...\", 第 N 行, 在 tearDown 中\n    self.conn.close()\nAttributeError: 'NoneType' 对象没有属性 'close'",
  "regex": "ERROR:\\ tearDown\\ \\(tests\\.test_foo\\.TestFoo\\)\\ \\.\\.\\.\\\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 references an attribute that setUp failed to assign (e.g., because setUp raised or was skipped), so the cleanup runs against an uninitialized value.",
  "root_cause_type": "generic",
  "root_cause_zh": "tearDown 引用了 setUp 未能赋值的属性（例如 setUp 抛出异常或被跳过），导致清理逻辑作用于未初始化的值。",
  "versions": [
    {
      "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 the error but leaks resources (open sockets, temp files) and hides genuine teardown bugs, causing cascading failures in later tests.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "addCleanup still calls the same code path; if the attribute is None the same AttributeError is raised, now reported as a cleanup error.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.94,
      "how": "def tearDown(self):\n    conn = getattr(self, 'conn', None)\n    if conn is not None:\n        conn.close()\n    super().tearDown()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.96,
      "how": "def setUp(self):\n    self.conn = connect()\n    self.addCleanup(self.conn.close)\n\n# addCleanup runs only if the resource was created",
      "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-04-25",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}