{
  "id": "python/unittest-mock-autospec-missing-attribute",
  "signature": "AttributeError: Mock object has no attribute 'some_method'",
  "signature_zh": "AttributeError: Mock 对象没有属性 'some_method'",
  "regex": "AttributeError:\\ Mock\\ object\\ has\\ no\\ attribute\\ 'some_method'",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Using `create_autospec` restricts the mock to the real object's attributes; if `some_method` is dynamically added or misspelled, access fails.",
  "root_cause_type": "generic",
  "root_cause_zh": "使用 `create_autospec` 将 mock 限制为真实对象的属性；如果 `some_method` 是动态添加的或拼写错误，访问会失败。",
  "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": "Loses the safety of autospec and may hide typos in method names.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Defeats the purpose of autospec and may not match the real signature.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "class MyClass:\n    def some_method(self): ...\n\nmock = create_autospec(MyClass)\nmock.some_method()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "mock = Mock(spec_set=['some_method', 'other_method'])",
      "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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}