New submission from webisteme <[email protected]>:
When calling `mock.patch` incorrectly, as in the following example, an uncaught
error is thrown:
```shell
>>> from unittest import mock
>>> class Foo:
... pass
...
>>> mock.patch(Foo())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/mock.py",
line 1624, in patch
getter, attribute = _get_target(target)
File
"/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/mock.py",
line 1469, in _get_target
target, attribute = target.rsplit('.', 1)
AttributeError: 'Foo' object has no attribute 'rsplit'
```
This can happen when confusing `mock.patch` with `mock.patch.object`. However,
the uncaught error is not informative, as it does not indicate that the wrong
type of object was passed to `mock.patch`.
----------
components: Library (Lib)
messages: 374339
nosy: webisteme
priority: normal
severity: normal
status: open
title: Uncaught AttributeError in unittest.mock._get_target
type: behavior
versions: Python 3.7
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41403>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com