diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2016-01-09 07:43:29 (GMT) |
---|---|---|
committer | Senthil Kumaran <senthil@uthcode.com> | 2016-01-09 07:43:29 (GMT) |
commit | 81bc927da7f1b2cc0d2be642810b084666f63264 (patch) | |
tree | 526e6abdaa667eedc6653fddf8b1ae5a20c10146 /Lib/unittest/mock.py | |
parent | cbe6356c4260c3f040124fe213d1fd85280bedfe (diff) | |
download | cpython-81bc927da7f1b2cc0d2be642810b084666f63264.zip cpython-81bc927da7f1b2cc0d2be642810b084666f63264.tar.gz cpython-81bc927da7f1b2cc0d2be642810b084666f63264.tar.bz2 |
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.py | 5 |
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) |