Skip to content

Commit d8bf494

Browse files
author
Barry McLarnon
committed
bpo-40126: Fix attribute out of scope during error handling in mock
1 parent 96c5f5a commit d8bf494

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

Lib/unittest/mock.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,7 @@ def decorate_callable(self, func):
12441244
def patched(*args, **keywargs):
12451245
extra_args = []
12461246
entered_patchers = []
1247+
patching = None
12471248

12481249
exc_info = tuple()
12491250
try:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fixed an issue in unittest.mock where an unhandled exception can be raised
2+
by decorate_callable if patched.patchings is cleared during cleanup of
3+
another decorator. This causes the patching variable to be undefined in the
4+
exception handler, leading to an UnboundLocalError being raised.

0 commit comments

Comments
 (0)