This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xtreak
Recipients hmvp, xtreak
Date 2018-09-14.10:10:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Can confirm this behavior on CPython master as well. It seems that when an attribute is deleted then a deleted flag is set for the attribute at . But when reset_mock is called it doesn't check for the deleted flag at

➜  cpython git:(master) ./python.exe ../backups/
Traceback (most recent call last):
  File "../backups/", line 5, in <module>
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/unittest/", line 546, in reset_mock
AttributeError: '_SentinelObject' object has no attribute 'reset_mock'

A simple patch would be to skip the deleted as below but some of the code in mock module raise an AttributeError. I don't know the correct behavior here. But applying the below patch and running tests with `./python.exe Lib/unittest/test/` doesn't cause any test failure.

diff --git a/Lib/unittest/ b/Lib/unittest/
index db1e642c00..700e2fb8b9 100644
--- a/Lib/unittest/
+++ b/Lib/unittest/
@@ -541,7 +541,7 @@ class NonCallableMock(Base):
             self._mock_side_effect = None
         for child in self._mock_children.values():
-            if isinstance(child, _SpecState):
+            if isinstance(child, _SpecState) or child is _deleted:
I will try to make a PR if it's ok.

Date User Action Args
2018-09-14 10:10:37xtreaksetrecipients: + xtreak, hmvp
2018-09-14 10:10:37xtreaksetmessageid: <>
2018-09-14 10:10:37xtreaklinkissue31177 messages
2018-09-14 10:10:37xtreakcreate