{
  "id": "python/unittest-mock-call-count-assertion",
  "signature": "AssertionError: Expected mock to have been called 3 times. Called 2 times.",
  "signature_zh": "断言错误：预期模拟被调用 3 次，实际被调用 2 次。",
  "regex": "AssertionError:\\ Expected\\ mock\\ to\\ have\\ been\\ called\\ 3\\ times\\.\\ Called\\ 2\\ times\\.",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The test asserts mock.assert_called_with or mock.assert_called_once, but the actual number of calls does not match the expectation, often due to conditional logic in the code under test.",
  "root_cause_type": "generic",
  "root_cause_zh": "测试断言了 mock.assert_called_with 或 mock.assert_called_once，但实际调用次数与预期不符，通常是由于被测试代码中的条件逻辑。",
  "versions": [
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Adding extra mock calls to meet the expected count may pass the test but does not reflect real behavior.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Using assert_any_call instead of assert_called_with may pass if the call exists but does not verify the exact number of calls.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Debug the code under test to understand the call pattern and adjust the expected count or the code logic.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "Use mock.call_count to get the actual count and assert conditionally: self.assertEqual(mock.call_count, 3)",
      "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": "2026-10-20",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}