# StopIteration: 

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

## Root Cause

A mock with side_effect set to an iterator (e.g., a list) has been called more times than there are items in the iterator.

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   def side_effect(*args, **kwargs):
    while True:
        yield 'value'

mock.side_effect = side_effect()
   ```
2. **** (95% success)
   ```
   mock.assert_called_once()  # or assert_called_with
This will fail earlier with a clearer message if called too many times.
   ```

## Dead Ends

- **** — This may mask the real issue of unexpected extra calls. (80% fail)
- **** — Changes behavior and may hide bugs. (70% fail)
