{
  "id": "python/attributeerror-mock-object-has-no-attribute",
  "signature": "AttributeError: Mock object has no attribute 'some_method'",
  "signature_zh": "属性错误：Mock 对象没有属性 'some_method'",
  "regex": "AttributeError:\\ Mock\\ object\\ has\\ no\\ attribute\\ 'some_method'",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A mock object is created without specifying the attribute, and the code tries to access an undefined attribute.",
  "root_cause_type": "generic",
  "root_cause_zh": "创建模拟对象时未指定属性，代码尝试访问未定义的属性。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding attribute via mock.attach_mock",
      "why_fails": "attach_mock is for attaching additional mocks, not simple attributes.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using mock.reset_mock()",
      "why_fails": "Reset clears call history but does not add missing attributes.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Configure mock with spec or autospec",
      "success_rate": 0.95,
      "how": "mock = Mock(spec=MyClass); mock.some_method.return_value = 42",
      "condition": "",
      "sources": []
    },
    {
      "action": "Set attribute directly on mock",
      "success_rate": 0.9,
      "how": "mock = Mock(); mock.some_method = MagicMock(return_value=42)",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-10-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}