{
  "id": "python/pytest-mock-patch-dict",
  "signature": "AttributeError: 'dict' object has no attribute 'items'",
  "signature_zh": "AttributeError: 'dict' 对象没有属性 'items'",
  "regex": "AttributeError:\\ 'dict'\\ object\\ has\\ no\\ attribute\\ 'items'",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A dictionary was patched with a Mock, but the code expects a real dictionary and calls dict methods like .items().",
  "root_cause_type": "generic",
  "root_cause_zh": "字典被 Mock 替换，但代码期望一个真实的字典并调用了 .items() 等字典方法。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "MagicMock supports magic methods but not dict-specific methods like .items() unless configured.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This defeats the purpose of the test and may cause other failures.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "patch.dict('module.my_dict', {'key': 'value'}) or use a simple class that implements the required methods.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "mock_dict = Mock()\nmock_dict.items.return_value = [('key', 'value')]\npatch('module.my_dict', mock_dict)",
      "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.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2026-01-20",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}