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__
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
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__'
Thanks @asottile for the patch. I think the original AttributeError is resolved with bpo-28919 where they were silenced. It seems similar to bpo-32153 though the exception occurs from mock instead of partial object as in bpo-32153. The fix was applied to 3.7+ and hence 3.6 was not fixed which enters security fix only mode shortly. The attached tests also pass on master and I think it will it be a good unittest addition to Lib/unittest/test/testmock/testwith.py (similar to bpo-32153) that has a couple of nested with statements for the same attribute. Adding cjw296 to the list.
to be honest, I don't recall exactly given it's been 2 and a half years since the original report with no activity.
if I recall correctly, this was encountered while upgrading the mock backport in yelp's monolithic repository.
I want to say the reason this was hard to "fix" properly was due to some blanket patches being applied in a base test case and then other test cases re-patching those methods to add more specific behaviour. This worked fine in python2.7 and all the way until python3.3 but then was broken by changes in python3.4
Fortunately, they've been fixed in python3.7. I guess I've been encouraged to write a patch with a test so it does not regress in the future
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
The text was updated successfully, but these errors were encountered: