{
  "id": "python/pytest-patch-stopall-early",
  "signature": "AttributeError: 'NoneType' object has no attribute 'get'",
  "signature_zh": "AttributeError: 'NoneType' 对象没有属性 'get'",
  "regex": "AttributeError:\\ 'NoneType'\\ object\\ has\\ no\\ attribute\\ 'get'",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A test calls `patch.stopall()` in a `finally` block, which removes patches set up by `setUp` for subsequent tests in the same class. Later tests see the real (or None) object instead of the mock.",
  "root_cause_type": "generic",
  "root_cause_zh": "测试在 `finally` 块中调用 `patch.stopall()`，这会移除同一类中 `setUp` 为后续测试设置的 patch。后续测试看到的是真实对象（或 None），而不是 mock。",
  "versions": [
    {
      "version": "3.10",
      "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": "tearDown runs after each test, so the same problem persists across tests in the class.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Hard to detect failure reliably; patches still leak between tests.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Use context managers or decorators so patches are scoped automatically:\n\n@patch('mymod.dep')\ndef test_x(mock_dep):\n    ...",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use `addCleanup` to stop patches at the right time:\n\nself.addCleanup(patcher.stop)",
      "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": "2025-08-11",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}