{
  "id": "python/unittest-mock-patch-attribute-error",
  "signature": "AttributeError: <class 'module'> does not have the attribute 'some_function'",
  "signature_zh": "属性错误：<class 'module'> 没有属性 'some_function'",
  "regex": "AttributeError:\\ <class\\ 'module'>\\ does\\ not\\ have\\ the\\ attribute\\ 'some_function'",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "Using @patch or patch.object with an incorrect target path (e.g., patching a non-existent attribute) causes an AttributeError when the mock is applied.",
  "root_cause_type": "generic",
  "root_cause_zh": "使用 @patch 或 patch.object 时，目标路径不正确（例如，修补不存在的属性）会在应用模拟时导致 AttributeError。",
  "versions": [
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Changing the patch target to a different module without verifying the attribute exists may still fail if the attribute is imported incorrectly.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Using patch.object with a class that has the attribute but misspelling the attribute name leads to a similar error.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Verify the exact attribute path: e.g., patch('mymodule.submodule.some_function') and ensure the attribute exists in the module.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Use patch.object with the actual object: patch.object(mymodule, 'some_function') after importing the module.",
      "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": "2025-03-08",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}