This can either be a function to be called when the mock is called, an iterable or an exception (class or instance) to be raised.
>>> mock = Mock() >>> mock.side_effect = Exception('Boom!') >>> mock() Traceback (most recent call last): ... Exception: Boom!
unittest.mock/Mock.side_effect
Mock.side_effect