# AssertionError: Expected mock to have been called 3 times. Called 2 times.

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

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

## Version Compatibility

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

## Workarounds

1. **** (85% success)
   ```
   Debug the code under test to understand the call pattern and adjust the expected count or the code logic.
   ```
2. **** (80% success)
   ```
   Use mock.call_count to get the actual count and assert conditionally: self.assertEqual(mock.call_count, 3)
   ```

## Dead Ends

- **** — Adding extra mock calls to meet the expected count may pass the test but does not reflect real behavior. (60% fail)
- **** — Using assert_any_call instead of assert_called_with may pass if the call exists but does not verify the exact number of calls. (50% fail)
