[issue45215] Add docs for Mock name and parent args and deprecation warning when wrong args are passed

Andrei Kulakov report at bugs.python.org
Thu Sep 16 16:39:22 EDT 2021


Andrei Kulakov <andrei.avk at gmail.com> added the comment:

I forgot to include example of the breakage:

>>> m=Mock(name=1)
>>> m
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ak/opensource/cpython2/Lib/unittest/mock.py", line 735, in __repr__
    name = self._extract_mock_name()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ak/opensource/cpython2/Lib/unittest/mock.py", line 732, in _extract_mock_name
    return ''.join(_name_list)
           ^^^^^^^^^^^^^^^^^^^
TypeError: sequence item 0: expected str instance, int found

>>> m=Mock(parent='foo')
>>> m
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ak/opensource/cpython2/Lib/unittest/mock.py", line 735, in __repr__
    name = self._extract_mock_name()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ak/opensource/cpython2/Lib/unittest/mock.py", line 719, in _extract_mock_name
    _name_list.append(_parent._mock_new_name + dot)
                      ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute '_mock_new_name'

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45215>
_______________________________________


More information about the Python-bugs-list mailing list