Skip to content

Commit 3c4edf2

Browse files
committed
Preserve only _patch.temp_original instead of _patch.original
1 parent a07d3b5 commit 3c4edf2

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

Lib/unittest/mock.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,14 +1486,6 @@ def is_local(self):
14861486
def is_local(self, value):
14871487
self._context.is_local = value
14881488

1489-
@property
1490-
def original(self):
1491-
return self._context.original
1492-
1493-
@original.setter
1494-
def original(self, value):
1495-
self._context.original = value
1496-
14971489
@property
14981490
def target(self):
14991491
return self._context.target
@@ -1503,12 +1495,12 @@ def target(self, value):
15031495
self._context.target = value
15041496

15051497
@property
1506-
def temp_original(self): # backwards compatibility
1507-
return self.original
1498+
def temp_original(self):
1499+
return self._context.original
15081500

15091501
@temp_original.setter
1510-
def temp_original(self, value): # backwards compatibility
1511-
self.original = value
1502+
def temp_original(self, value):
1503+
self._context.original = value
15121504

15131505
def __enter__(self):
15141506
"""Perform the patch."""
@@ -1672,16 +1664,16 @@ def __exit__(self, *exc_info):
16721664
if not self.is_started:
16731665
return
16741666

1675-
if self.is_local and self.original is not DEFAULT:
1676-
setattr(self.target, self.attribute, self.original)
1667+
if self.is_local and self.temp_original is not DEFAULT:
1668+
setattr(self.target, self.attribute, self.temp_original)
16771669
else:
16781670
delattr(self.target, self.attribute)
16791671
if not self.create and (not hasattr(self.target, self.attribute) or
16801672
self.attribute in ('__doc__', '__module__',
16811673
'__defaults__', '__annotations__',
16821674
'__kwdefaults__')):
16831675
# needed for proxy objects like django settings
1684-
setattr(self.target, self.attribute, self.original)
1676+
setattr(self.target, self.attribute, self.temp_original)
16851677

16861678
exit_stack = self._context.exit_stack
16871679
self._context = None

0 commit comments

Comments
 (0)