{
  "id": "python/pytest-mock-patch-target",
  "signature": "AttributeError: <module 'app.services' from '/app/services.py'> does not have the attribute 'send_email'",
  "signature_zh": "AttributeError: <模块 'app.services'> 没有属性 'send_email'",
  "regex": "AttributeError:\\ <module\\ 'app\\.services'\\ from\\ '/app/services\\.py'>\\ does\\ not\\ have\\ the\\ attribute\\ 'send_email'",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "patch() targets a name that does not exist in the module at patch time, usually because the function is imported under a different name, lives in another module, or the import happens at call time.",
  "root_cause_type": "generic",
  "root_cause_zh": "patch() 在打补丁时指向了模块中不存在的名称，通常因为函数以不同名称导入、位于另一个模块或调用时才导入。",
  "versions": [
    {
      "version": "3.8",
      "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": "create=True adds the attribute for the mock but does not change the code under test, so the real function is still called.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If the consumer did `from x import send_email`, patching x.send_email does not affect the local reference.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "Patch where the name is looked up (the consumer module):\n\nwith patch('app.notifications.send_email') as m:\n    notify_user()\n    m.assert_called_once()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "Verify the actual attribute name:\n\npython -c \"import app.services; print([n for n in dir(app.services) if 'email' in n])\"",
      "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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-08",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}