@@ -461,14 +461,19 @@ the `new_callable` argument to `patch`.
461461 .. attribute :: side_effect
462462
463463 This can either be a function to be called when the mock is called,
464- or an exception (class or instance) to be raised.
464+ an iterable or an exception (class or instance) to be raised.
465465
466466 If you pass in a function it will be called with same arguments as the
467467 mock and unless the function returns the :data: `DEFAULT ` singleton the
468468 call to the mock will then return whatever the function returns. If the
469469 function returns :data: `DEFAULT ` then the mock will return its normal
470470 value (from the :attr: `return_value `).
471471
472+ If you pass in an iterable, it is used to retrieve an iterator which
473+ must yield a value on every call. This value can either be an exception
474+ instance to be raised, or a value to be returned from the call to the
475+ mock (:data: `DEFAULT ` handling is identical to the function case).
476+
472477 An example of a mock that raises an exception (to test exception
473478 handling of an API):
474479
@@ -486,11 +491,7 @@ the `new_callable` argument to `patch`.
486491 >>> mock(), mock(), mock()
487492 (3, 2, 1)
488493
489- The :attr: `side_effect ` function is called with the same arguments as the
490- mock (so it is wise for it to take arbitrary args and keyword
491- arguments) and whatever it returns is used as the return value for
492- the call. The exception is if :attr: `side_effect ` returns :data: `DEFAULT `,
493- in which case the normal :attr: `return_value ` is used.
494+ Using a callable:
494495
495496 >>> mock = Mock(return_value = 3 )
496497 >>> def side_effect (* args , ** kwargs ):
@@ -1011,7 +1012,7 @@ patch
10111012 used.
10121013
10131014 A more powerful form of *spec * is *autospec *. If you set ``autospec=True ``
1014- then the mock with be created with a spec from the object being replaced.
1015+ then the mock will be created with a spec from the object being replaced.
10151016 All attributes of the mock will also have the spec of the corresponding
10161017 attribute of the object being replaced. Methods and functions being mocked
10171018 will have their arguments checked and will raise a :exc: `TypeError ` if they are
0 commit comments