summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/mock.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r--Lib/unittest/mock.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 8cedcb4..8378b0f 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -891,7 +891,10 @@ class CallableMixin(Base):
raise effect
if not _callable(effect):
- return next(effect)
+ result = next(effect)
+ if _is_exception(result):
+ raise result
+ return result
ret_val = effect(*args, **kwargs)
if ret_val is DEFAULT:
@@ -931,8 +934,9 @@ class Mock(CallableMixin, NonCallableMock):
arguments as the mock, and unless it returns `DEFAULT`, the return
value of this function is used as the return value.
- Alternatively `side_effect` can be an exception class or instance. In
- this case the exception will be raised when the mock is called.
+ If `side_effect` is an iterable then each call to the mock will return
+ the next value from the iterable. If any of the members of the iterable
+ are exceptions they will be raised instead of returned.
If `side_effect` is an iterable then each call to the mock will return
the next value from the iterable.