summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/mock.py
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2016-01-09 07:44:10 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2016-01-09 07:44:10 (GMT)
commitb94591c2bfc64f98c9daf35d2481424ca116e077 (patch)
tree0461051342a8c50852fc2e3234a5a5f14aeccb7f /Lib/unittest/mock.py
parenta85e927e39b0ef3637c0bb6efa851494b8d92662 (diff)
parent81bc927da7f1b2cc0d2be642810b084666f63264 (diff)
downloadcpython-b94591c2bfc64f98c9daf35d2481424ca116e077.zip
cpython-b94591c2bfc64f98c9daf35d2481424ca116e077.tar.gz
cpython-b94591c2bfc64f98c9daf35d2481424ca116e077.tar.bz2
merge from 3.5
Issue #22138: Fix mock.patch behavior when patching descriptors. Restore original values after patching. Patch contributed by Sean McCully.
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r--Lib/unittest/mock.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 99ce1e2..976f663 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -1332,7 +1332,10 @@ class _patch(object):
setattr(self.target, self.attribute, self.temp_original)
else:
delattr(self.target, self.attribute)
- if not self.create and not hasattr(self.target, self.attribute):
+ if not self.create and (not hasattr(self.target, self.attribute) or
+ self.attribute in ('__doc__', '__module__',
+ '__defaults__', '__annotations__',
+ '__kwdefaults__')):
# needed for proxy objects like django settings
setattr(self.target, self.attribute, self.temp_original)