mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #22138: Fix mock.patch behavior when patching descriptors. Restore
original values after patching. Patch contributed by Sean McCully.
This commit is contained in:
parent
cbe6356c42
commit
81bc927da7
3 changed files with 33 additions and 1 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue