{
  "id": "python/unittest-mock-side-effect-iterator-exhausted",
  "signature": "StopIteration: ",
  "signature_zh": "StopIteration: ",
  "regex": "StopIteration:\\ ",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A mock with side_effect set to an iterator (e.g., a list) has been called more times than there are items in the iterator.",
  "root_cause_type": "generic",
  "root_cause_zh": "一个 mock 的 side_effect 设置为迭代器（例如列表），但被调用的次数超过了迭代器中的项目数。",
  "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": "This may mask the real issue of unexpected extra calls.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Changes behavior and may hide bugs.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "def side_effect(*args, **kwargs):\n    while True:\n        yield 'value'\n\nmock.side_effect = side_effect()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "mock.assert_called_once()  # or assert_called_with\nThis will fail earlier with a clearer message if called too many times.",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-20",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}