Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upbpo-38473: Handle autospecced functions and methods used with attach_mock #16784
Conversation
@@ -820,7 +820,16 @@ def _get_call_signature_from_name(self, name): | |||
break | |||
else: | |||
children = child._mock_children |
This comment has been minimized.
This comment has been minimized.
tirkarthi
Oct 14, 2019
Author
Member
Note to self, reviewer : Do we need to default to empty dictionary too guarding against AttributeError
for _mock_children
?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Sorry, I somehow forgot this issue in my list. Would appreciate a review of this since it caused a regression. cc: @mariocj89 Thanks |
sig = child._spec_signature | ||
try: | ||
sig = child._spec_signature | ||
except AttributeError: |
This comment has been minimized.
This comment has been minimized.
mariocj89
Jan 23, 2020
Contributor
In which situation will we fall here? Can you add a tests that exercises this?
This comment has been minimized.
This comment has been minimized.
tirkarthi
Jan 23, 2020
Author
Member
I couldn't think of a situation that would get to this as autospecced ones should have this. But given that this was a regression of the previous change without tests catching it I added it as a fallback to have signature as None in case there are scenarios not tested here or try to use getattr
with None as default.
This comment has been minimized.
This comment has been minimized.
mariocj89
Jan 23, 2020
Contributor
I personally don't like the idea of having code "just if", but you wrote this function initially, so...
This comment has been minimized.
This comment has been minimized.
cjw296
Jan 24, 2020
Contributor
If we can't prove it's needed, let's drop it until we can. The backport caught up now, just want to get as many upstream PRs merged first before releasing, so we should get good feedback if this code can be reached.
This comment has been minimized.
This comment has been minimized.
I'm afraid I don't have a lot to offer here, since I've never used |
…ck object.
This comment has been minimized.
This comment has been minimized.
I have removed the Line 434 in 161e7b3 _spec_signature seems to be always initialized with None on mock object. The attribute error was due to inner mock object not being extracted which is fixed. I was slightly concerned since the tests didn't catch it and caused a regression. I understand your points on having an untested block as a fallback. I will revisit this if there is a report of it in future. Thanks for your inputs.
|
@@ -817,6 +817,12 @@ def _get_call_signature_from_name(self, name): | |||
if child is None or isinstance(child, _SpecState): | |||
break | |||
else: | |||
# If an autospecced object is attached using attach_mock the | |||
# child would be a function with mock object as attribute from | |||
# which signature has to be derived. If there is no signature |
This comment has been minimized.
This comment has been minimized.
mariocj89
Jan 24, 2020
Contributor
You might want to review this comment (maybe remove it as well and include it in the commit message).
This comment has been minimized.
This comment has been minimized.
tirkarthi
Jan 24, 2020
Author
Member
Thanks for catching this. I prefer to keep it here with the part about fallback updated since it will be good to know why extract_mock is needed. I will add this in the comment over this change.
66b00a9
into
python:master
This comment has been minimized.
This comment has been minimized.
miss-islington
commented
Jan 24, 2020
Thanks @tirkarthi for the PR, and @cjw296 for merging it |
This comment has been minimized.
This comment has been minimized.
miss-islington
commented
Jan 24, 2020
Thanks @tirkarthi for the PR, and @cjw296 for merging it |
…mock (pythonGH-16784) (cherry picked from commit 66b00a9) Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Jan 24, 2020
GH-18166 is a backport of this pull request to the 3.7 branch. |
…mock (pythonGH-16784) (cherry picked from commit 66b00a9) Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Jan 24, 2020
GH-18167 is a backport of this pull request to the 3.8 branch. |
tirkarthi commentedOct 14, 2019
•
edited
Extract signature from the inner mock object for methods/functions autospecced and attached to a mock object using
attach_mock
.https://bugs.python.org/issue38473