Visitar URL original
bpo-21478: Autospec functions should propagate mock calls to parent by tirkarthi · Pull Request #11273 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20220524115945/https://github.com/python/cpython/pull/11273
Skip to content
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

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

@tirkarthi tirkarthi commented Feb 24, 2019

@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

@cjw296 cjw296 Feb 24, 2019

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

@tirkarthi tirkarthi Feb 24, 2019

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.

cjw296
cjw296 approved these changes Feb 25, 2019
@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Feb 25, 2019

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 issue Feb 25, 2019
(cherry picked from commit 9c3f284)

Co-authored-by: Xtreak <tir.karthi@gmail.com>
@cjw296 cjw296 merged commit 9c3f284 into python:master Feb 25, 2019
5 checks passed
cjw296 pushed a commit that referenced this issue Mar 3, 2019
…2039)

(cherry picked from commit 9c3f284)

Co-authored-by: Xtreak <tir.karthi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants