Skip to content

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

Merged
cjw296 merged 1 commit into
python:masterfrom
tirkarthi:bpo21478
Feb 25, 2019
Merged

bpo-21478: Autospec functions should propagate mock calls to parent#11273
cjw296 merged 1 commit into
python:masterfrom
tirkarthi:bpo21478

Conversation

@tirkarthi

@tirkarthi tirkarthi commented Dec 21, 2018

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
(cherry picked from commit 9c3f284)

Co-authored-by: Xtreak <tir.karthi@gmail.com>
@cjw296
cjw296 merged commit 9c3f284 into python:master Feb 25, 2019
cjw296 pushed a commit that referenced this pull request 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants