diff options
Diffstat (limited to 'mock.py')
-rw-r--r-- | mock.py | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -1153,6 +1153,7 @@ class _patch(object): # can't use try...except...finally because of Python 2.4 # compatibility + exc_info = tuple() try: try: for patching in patched.patchings: @@ -1171,11 +1172,13 @@ class _patch(object): # the patcher may have been started, but an exception # raised whilst entering one of its additional_patchers entered_patchers.append(patching) + # Pass the exception to __exit__ + exc_info = sys.exc_info() # re-raise the exception raise finally: for patching in reversed(entered_patchers): - patching.__exit__() + patching.__exit__(*exc_info) patched.patchings = [self] if hasattr(func, 'func_code'): @@ -1317,7 +1320,7 @@ class _patch(object): del self.target for patcher in reversed(self.additional_patchers): if _is_started(patcher): - patcher.__exit__() + patcher.__exit__(*_) start = __enter__ stop = __exit__ |