gh-76273: Fix autospec mocking of instance and class methods#146526
gh-76273: Fix autospec mocking of instance and class methods#146526stephenfin wants to merge 1 commit intopython:mainfrom
Conversation
Currently, when patching instance / class methods with autospec, their
self / cls arguments are not consumed, causing call asserts to fail
(they expect an instance / class reference as the first argument).
Example:
from unittest import mock
class Something(object):
def foo(self, a, b, c, d):
pass
with mock.patch.object(Something, 'foo', autospec=True):
s = Something()
s.foo()
Fix this by skipping the first argument when presented with a method.
Based on python#4476
Signed-off-by: Stephen Finucane <stephen@that.guru>
Co-authored-by: Claudiu Belu <cbelu@cloudbasesolutions.com>
|
Hi! Nice to see some work on this. Btw, we generally avoid force pushes. |
Understood. I've got a small bit more work to do this on to resolve the |
Yes, all PRs are squashed on merge.
I see! It's in https://devguide.python.org/getting-started/pull-request-lifecycle/#don-t-force-push. Maybe we can make it more visible elsewhere, what do you think? Let me know what you had read before you created the PR, maybe we can add it there :-) Thanks for saying that you didn't see that note. |
Currently, when patching instance / class methods with
autospec, theirself/clsarguments are not consumed, causing call asserts to fail (they expect an instance / class reference as the first argument).Example:
Fix this by skipping the first argument when presented with a method.
Based on #4476 with the changes to the
Mocksignature stripped out and left for a separate, follow-up PR.