# StopIteration: raised by side_effect list exhausted

- **ID:** `python/unittest-mock-side-effect`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A mock's side_effect was set to a finite list, and the code under test called the mock more times than the list length, raising StopIteration.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8 | active | — | — |
| 3.12 | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Use a callable for side_effect that handles any number of calls:

m.side_effect = lambda x: x * 2
   ```
2. **** (88% success)
   ```
   Extend the list to match the expected call count and assert:

m.side_effect = [1, 2, 3]
run()
assert m.call_count == 3
   ```

## Dead Ends

- **** — This hides the real issue: the test exercises more calls than expected, or the list is too short. (85% fail)
- **** — Adding one None only delays the problem; a subsequent call raises StopIteration again. (80% fail)
