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-38932: Make Mock.reset_mock() pass return_value and side_effect values to reset_mock on child mock objects #17409

Merged
merged 3 commits into from Jan 25, 2020

Conversation

@vegarsti
Copy link
Contributor

vegarsti commented Nov 27, 2019

Issue on issue tracker.

The Mock class from unittest has a method reset_mock, which takes optional arguments return_value and side_effect, both with default values False.

In the body of reset_mock, reset_mock is called recursively on all the _mock_children of the Mock object. However, here the arguments are not passed. I realize this may be a feature and not a bug, but this caused some confusion in the test suite at the company where I work, where we thought we reset our mocked objects properly, but we didn't.

This means that if you have a Mock object with children that are also mocked, and methods on these have been directly mocked, then it is not enough to call reset_mock on the parent object.

This is my first attempt at a contribution to Python. I have most likely done something wrong, and I will do my best to help further.

https://bugs.python.org/issue38932

@the-knights-who-say-ni

This comment has been minimized.

Copy link

the-knights-who-say-ni commented Nov 27, 2019

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@vegarsti

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@vegarsti vegarsti changed the title bpo-38932: Make unittest.mock.Mock.reset_mock pass return_value and side_effect values to reset_mock on child mock objects bpo-38932: Make unittest.mock.Mock.reset_mock() pass return_value and side_effect values to reset_mock on child mock objects Nov 27, 2019
@vegarsti vegarsti changed the title bpo-38932: Make unittest.mock.Mock.reset_mock() pass return_value and side_effect values to reset_mock on child mock objects bpo-38932: Make Mock.reset_mock() pass return_value and side_effect values to reset_mock on child mock objects Nov 27, 2019
@csabella csabella requested review from tirkarthi and lisroach Jan 17, 2020
@cjw296
cjw296 approved these changes Jan 25, 2020
Copy link
Contributor

cjw296 left a comment

This looks good to go but you need to add the NEWS entry.

@vegarsti

This comment has been minimized.

Copy link
Contributor Author

vegarsti commented Jan 25, 2020

@cjw296: Great, thanks! Will do!

@cjw296 cjw296 merged commit aef7dc8 into python:master Jan 25, 2020
9 checks passed
9 checks passed
Docs
Details
Windows (x86)
Details
Windows (x64)
Details
macOS
Details
Ubuntu
Details
Azure Pipelines PR #20200125.13 succeeded
Details
bedevere/issue-number Issue number 38932 found
Details
bedevere/news News entry found in Misc/NEWS.d
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.