New submission from Claudiu Belu <cb...@cloudbasesolutions.com>: If an object's attribute is a partial function, mock.create_autospec will fail while trying to copy the partial functions' details to the mocked function, as the partial function does not have the __name__ attribute.
Example: import functools from unittest import mock class Proxy(object): def __init__(self, obj): self.obj def __getattr__(self, name): return functools.partial(self.__run_method, name) def __run_method(self, name, *args, **kwargs): return getattr(self.obj, name)(*args, **kwargs) a = mock.Mock() proxy = Proxy(a) mock.create_autospec(proxy) Output: Traceback (most recent call last): File "py3_mock_functools.py", line 20, in <module> mock.create_autospec(proxy) File "/usr/lib/python3.5/unittest/mock.py", line 2156, in create_autospec _check_signature(spec, mock, is_type, instance) File "/usr/lib/python3.5/unittest/mock.py", line 112, in _check_signature _copy_func_details(func, checksig) File "/usr/lib/python3.5/unittest/mock.py", line 117, in _copy_func_details funcopy.__name__ = func.__name__ AttributeError: 'functools.partial' object has no attribute '__name__' ---------- components: Library (Lib) messages: 307115 nosy: cbelu priority: normal severity: normal status: open title: mock.create_autospec fails if an attribute is a partial function versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32153> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com