# AssertionError: Expected call: mock_function(1, 2, 3)
Actual call: mock_function(1, 2, 4)

- **ID:** `python/unittest-mock-assert-called-with-argument-mismatch`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |

## Workarounds

1. **Debug the code under test to understand why arguments differ, then adjust the test or fix the code** (90% success)
   ```
   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.
   ```
2. **Use `assert_called_once_with` with flexible matchers like `unittest.mock.ANY` or custom matchers for acceptable variations** (80% success)
   ```
   from unittest.mock import ANY
mock_function.assert_called_once_with(1, 2, ANY)
This allows the third argument to be anything, but still verifies the first two.
   ```

## Dead Ends

- **Changing the expected arguments to match the actual call without investigating why the code under test produces different values** — This masks the real issue in the code under test, potentially allowing bugs to go undetected. (70% fail)
- **Using `assert_any_call` instead of `assert_called_with` to ignore argument differences** — This weakens the test by not verifying the exact arguments, which may hide important regressions. (50% fail)
