{
  "id": "python/unittest-mock-side-effect-exception",
  "signature": "ValueError: side_effect must be a callable or iterable, got <class 'int'>",
  "signature_zh": "值错误：side_effect 必须是可调用对象或可迭代对象，得到 <class 'int'>",
  "regex": "ValueError:\\ side_effect\\ must\\ be\\ a\\ callable\\ or\\ iterable,\\ got\\ <class\\ 'int'>",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "在 Mock 中设置 side_effect 时提供了非法的类型，如整数或字符串。",
  "root_cause_type": "generic",
  "root_cause_zh": "在 Mock 中设置 side_effect 时提供了非法的类型，如整数或字符串。",
  "versions": [
    {
      "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": "",
      "why_fails": "可能无法模拟异常或序列行为。",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "列表会被迭代，如果元素不是可调用，仍会出错。",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 1.0,
      "how": "`mock.side_effect = lambda x: x + 1` 或 `mock.side_effect = [1, 2, 3]` 用于序列返回值。",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "`mock.side_effect = Exception('错误')` 模拟异常抛出。",
      "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-10-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}