{
  "id": "python/unittest-mock-call-count-error",
  "signature": "AssertionError: Expected mock to be called 2 times. Called 1 times.",
  "signature_zh": "断言错误：预期模拟被调用 2 次。实际被调用 1 次。",
  "regex": "AssertionError:\\ Expected\\ mock\\ to\\ be\\ called\\ 2\\ times\\.\\ Called\\ 1\\ times\\.",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "The code under test calls the mocked function fewer times than expected, often due to conditional logic or early returns.",
  "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": "Increasing the expected call count to match actual calls",
      "why_fails": "This masks the bug in the code that is not calling the function enough times.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding mock.reset_mock() before assertion",
      "why_fails": "Resetting the mock clears call history, making the assertion pass incorrectly.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Debug the code to understand why the function is not called enough times.",
      "success_rate": 0.9,
      "how": "Add print statements or use a debugger to trace the execution path.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use mock.call_args_list to inspect actual calls and compare with expected.",
      "success_rate": 0.85,
      "how": "assert mock.call_args_list == [call(arg1), call(arg2)]",
      "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-03-25",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}