bpo-21478: Autospec functions should propagate mock calls to parent#11273
Merged
Conversation
Member
Author
|
@cjw296 @mariocj89 It would be helpful if you can review this. |
cjw296
reviewed
Feb 24, 2019
| mock.child(1, 2) | ||
|
|
||
| self.assertRaises(TypeError, mock.child, 1) | ||
| self.assertEqual(mock.mock_calls, [call.child(1, 2)]) |
Contributor
There was a problem hiding this comment.
What was the outcome here before your fix?
Member
Author
There was a problem hiding this comment.
mock.mock_calls would be an empty list though the child mock was called. It's a case where create_autospec returns a function object with mock attached to it in the mock attribute instead of a mock.
cjw296
approved these changes
Feb 25, 2019
Contributor
|
Thanks @tirkarthi for the PR, and @cjw296 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Feb 25, 2019
(cherry picked from commit 9c3f284) Co-authored-by: Xtreak <tir.karthi@gmail.com>
cjw296
pushed a commit
that referenced
this pull request
Mar 3, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a function is passed to
create_autospecthen a function object is returned where the mock is attached to the object with the attribute namemock. Set parent against the mock attribute so that calls to children are propagated to the parent.https://bugs.python.org/issue21478