Skip to content

bpo-21478: Autospec functions should propagate mock calls to parent #11273

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

Merged
merged 1 commit into from
Feb 25, 2019

Conversation

tirkarthi
Copy link
Member

@tirkarthi tirkarthi commented Dec 21, 2018

When a function is passed to create_autospec then a function object is returned where the mock is attached to the object with the attribute name mock . Set parent against the mock attribute so that calls to children are propagated to the parent.

https://bugs.python.org/issue21478

@tirkarthi
Copy link
Member Author

@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)])
Copy link
Contributor

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?

Copy link
Member Author

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.

@miss-islington
Copy link
Contributor

Thanks @tirkarthi for the PR, and @cjw296 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 25, 2019
@cjw296 cjw296 merged commit 9c3f284 into python:master Feb 25, 2019
cjw296 pushed a commit that referenced this pull request Mar 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants