Title: unittest mock's reset_mock throws an error when an attribute has been deleted
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: hmvp
Priority: normal Keywords:

Created on 2017-08-10 14:22 by hmvp, last changed 2017-08-10 14:22 by hmvp.

Messages (1)
msg300090 - (view) Author: Hmvp (hmvp) Date: 2017-08-10 14:22
When using a mock and deleting a attribute reset_mock cannot be used anymore since it tries to call reset_mock on the _deleted sentinel value.

Reproduction path:
from unittest.mock import MagicMock
mock = MagicMock()
mock.a = 'test'
del mock.a

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/unittest/", line 544, in reset_mock
AttributeError: '_SentinelObject' object has no attribute 'reset_mock'

Expected result:
mock is reset without throwing an exception and the 'a' attribute is no longer in a deleted state

Only checked 3.5 and current master if bug is present
Date User Action Args
2017-08-10 14:22:19hmvpcreate