Can a mock side_effect iterator be reset after it has been exhausted?

Note that since Python 3.6, you can reset the mock side_effect and return_value with:

mock.reset_mock(return_value=True, side_effect=True)

From the docs:

In case you want to reset return_value or side_effect, then pass the corresponding parameter as True. Child mocks and the return value mock (if any) are reset as well.


As user2357112 commented, reassigning side_effect will solve you problem.

>>> from mock import MagicMock
>>>
>>> lst = [1, 2]
>>> mock = MagicMock(side_effect=lst)
>>> mock(), mock()
(1, 2)
>>> mock.side_effect = lst  # <-------
>>> mock(), mock()
(1, 2)