{
  "id": "python/unittest-mock-patch-wrong-target",
  "signature": "AttributeError: <module 'module_name' from '/path/to/module.py'> does not have the attribute 'function_name'",
  "signature_zh": "属性错误：模块 'module_name' 没有属性 'function_name'",
  "regex": "AttributeError:\\ <module\\ 'module_name'\\ from\\ '/path/to/module\\.py'>\\ does\\ not\\ have\\ the\\ attribute\\ 'function_name'",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "Mock patch target is incorrect; patching the module path instead of the location where the function is used.",
  "root_cause_type": "generic",
  "root_cause_zh": "Mock patch 目标错误；修补了模块路径，而不是函数被使用的位置。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "If the function is imported into another module, patching the original module doesn't affect the imported reference.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "patch.object requires an existing attribute; if the attribute doesn't exist, it raises AttributeError.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "@patch('module_where_used.function_name')\ndef test_something(mock_func):\n    ...",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "@patch('module_name.function_name', create=True)",
      "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-01-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}