New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-21478: Autospec functions should propagate mock calls to parent #11273
Conversation
|
@cjw296 @mariocj89 It would be helpful if you can review this. |
| mock.child(1, 2) | ||
|
|
||
| self.assertRaises(TypeError, mock.child, 1) | ||
| self.assertEqual(mock.mock_calls, [call.child(1, 2)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the outcome here before your fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
|
Thanks @tirkarthi for the PR, and @cjw296 for merging it |
(cherry picked from commit 9c3f284) Co-authored-by: Xtreak <tir.karthi@gmail.com>


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