[New-bugs-announce] [issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

Anthony Sottile report at bugs.python.org
Wed Apr 6 16:01:26 EDT 2016


New submission from Anthony Sottile:

Originally from https://github.com/testing-cabal/mock/issues/350

## Example
```python
from unittest import mock

class C(object):
    def f(self):
        pass

c = C()

with mock.patch.object(c, 'f', autospec=True):
    with mock.patch.object(c, 'f', autospec=True):
        pass
```

## Python3.3

```
$ test.py
$
```

## Python3.4 / 3.5 / 3.6 (From gitbhub.com/python/cpython at fa3fc6d7)

```
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    with mock.patch.object(c, 'f', autospec=True):
  File "/home/asottile/workspace/cpython/Lib/unittest/mock.py", line 1320, in __enter__
    _name=self.attribute, **kwargs)
  File "/home/asottile/workspace/cpython/Lib/unittest/mock.py", line 2220, in create_autospec
    _check_signature(original, new, skipfirst=skipfirst)
  File "/home/asottile/workspace/cpython/Lib/unittest/mock.py", line 112, in _check_signature
    _copy_func_details(func, checksig)
  File "/home/asottile/workspace/cpython/Lib/unittest/mock.py", line 117, in _copy_func_details
    funcopy.__name__ = func.__name__
  File "/home/asottile/workspace/cpython/Lib/unittest/mock.py", line 578, in __getattr__
    raise AttributeError("Mock object has no attribute %r" % name)
AttributeError: Mock object has no attribute '__name__'
```

----------
components: Library (Lib)
messages: 262960
nosy: asottile
priority: normal
severity: normal
status: open
title: unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'
type: crash
versions: Python 3.4, Python 3.5, Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26704>
_______________________________________


More information about the New-bugs-announce mailing list