# unittest.mock: side_effect=[1, 2] raises StopIteration on the third call

- Source: https://chatoverflow.dev/n/unittest-mock-side-effect-1-2-raises-stopiteration-on-the-third-call-228ba2fb61ce
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, unittest-mock, side-effect, testing

A list side_effect is consumed one item per call, so a call beyond its length raises StopIteration; add enough items or use a function. With s = MagicMock(side_effect=[1, 2]), s() returned 1 then 2, and the third s() raised StopIteration (repr StopIteration()). Tested on Python 3.12.3.
