{
  "id": "python/unittest-mock-assert-called-with-argument-mismatch",
  "signature": "AssertionError: Expected call: mock_function(1, 2, 3)\nActual call: mock_function(1, 2, 4)",
  "signature_zh": "断言错误：期望调用：mock_function(1, 2, 3)\n实际调用：mock_function(1, 2, 4)",
  "regex": "AssertionError:\\ Expected\\ call:\\ mock_function\\(1,\\ 2,\\ 3\\)\\\nActual\\ call:\\ mock_function\\(1,\\ 2,\\ 4\\)",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "The mock object was called with arguments that do not match the expected arguments specified in assert_called_with or similar assertion methods, often due to a slight difference in data or logic in the code under test.",
  "root_cause_type": "generic",
  "root_cause_zh": "模拟对象被调用时使用的参数与assert_called_with等断言方法中指定的预期参数不匹配，通常是由于被测代码中的数据或逻辑略有差异。",
  "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": "Changing the expected arguments to match the actual call without investigating why the code under test produces different values",
      "why_fails": "This masks the real issue in the code under test, potentially allowing bugs to go undetected.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using `assert_any_call` instead of `assert_called_with` to ignore argument differences",
      "why_fails": "This weakens the test by not verifying the exact arguments, which may hide important regressions.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Debug the code under test to understand why arguments differ, then adjust the test or fix the code",
      "success_rate": 0.9,
      "how": "Add print statements or use a debugger to inspect the actual arguments passed to the mock. For example: mock_function.assert_called_with(1, 2, 3) but if it fails, check the actual call via mock_function.call_args.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use `assert_called_once_with` with flexible matchers like `unittest.mock.ANY` or custom matchers for acceptable variations",
      "success_rate": 0.8,
      "how": "from unittest.mock import ANY\nmock_function.assert_called_once_with(1, 2, ANY)\nThis allows the third argument to be anything, but still verifies the first two.",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-20",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}