# StopIteration: 
# raised inside test where side_effect list was consumed

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

## Root Cause

A Mock's side_effect was set to a finite list, but the code under test calls the mock more times than the list has entries; the extra call raises StopIteration.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   mock.get.side_effect = lambda key: {'a': 1, 'b': 2}.get(key, 0)
   ```
2. **** (88% success)
   ```
   from itertools import chain, repeat
mock.get.side_effect = chain([1, 2], repeat(0))
   ```

## Dead Ends

- **** — Fixes the current call count but breaks again when the code loops over a different-sized input. (75% fail)
- **** — Loses the ability to return different values per call, which is often the whole point of the test. (70% fail)
