bpo-20239: Allow repeated deletion of unittest.mock.Mock attributes (GH-11629)
* Allow repeated deletion of unittest.mock.Mock attributes
* fixup! Allow repeated deletion of unittest.mock.Mock attributes
* fixup! fixup! Allow repeated deletion of unittest.mock.Mock attributes
(cherry picked from commit 222d303ade8aadf0adcae5190fac603bdcafe3f0)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 955af5d..42fbc22 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -728,11 +728,10 @@
# not set on the instance itself
return
- if name in self.__dict__:
- object.__delattr__(self, name)
-
obj = self._mock_children.get(name, _missing)
- if obj is _deleted:
+ if name in self.__dict__:
+ super().__delattr__(name)
+ elif obj is _deleted:
raise AttributeError(name)
if obj is not _missing:
del self._mock_children[name]