# AssertionError: Expected mock to be called 2 times. Called 1 times.

- **ID:** `python/unittest-mock-call-count-error`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The code under test calls the mocked function fewer times than expected, often due to conditional logic or early returns.

## Version Compatibility

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

## Workarounds

1. **Debug the code to understand why the function is not called enough times.** (90% success)
   ```
   Add print statements or use a debugger to trace the execution path.
   ```
2. **Use mock.call_args_list to inspect actual calls and compare with expected.** (85% success)
   ```
   assert mock.call_args_list == [call(arg1), call(arg2)]
   ```

## Dead Ends

- **Increasing the expected call count to match actual calls** — This masks the bug in the code that is not calling the function enough times. (80% fail)
- **Adding mock.reset_mock() before assertion** — Resetting the mock clears call history, making the assertion pass incorrectly. (70% fail)
