{
  "id": "python/unittest-mock-magicmock-not-callable",
  "signature": "TypeError: 'MagicMock' object is not callable",
  "signature_zh": "TypeError: 'MagicMock' 对象不可调用",
  "regex": "TypeError:\\ 'MagicMock'\\ object\\ is\\ not\\ callable",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A MagicMock instance was used where a callable is expected, but the mock was not configured to be callable, or the mock's return_value was accessed incorrectly.",
  "root_cause_type": "generic",
  "root_cause_zh": "在需要可调用对象的地方使用了 MagicMock 实例，但该 mock 未配置为可调用，或者错误地访问了 mock 的 return_value。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Mock is also not callable by default. The issue is configuration, not the mock class.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If the mock is not callable, adding parentheses will still raise TypeError. The mock must be configured as callable.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "mock_func = MagicMock()\nmock_func.return_value = 42\nassert mock_func() == 42",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "mock_func = MagicMock()\nmock_func.side_effect = lambda x: x * 2\nassert mock_func(5) == 10",
      "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-07-12",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}