Skip to content

Conversation

@vegarsti
Copy link
Contributor

@vegarsti 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
Copy link

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
Copy link
Contributor

@cjw296 cjw296 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@vegarsti
Copy link
Contributor Author

@cjw296: Great, thanks! Will do!

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.

4 participants