Skip to content

Conversation

@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Dec 8, 2018

  • tests: Further validate wraps functionality in unittest.mock.Mock

Add more tests to validate how wraps interacts with other features of
mocks.

  • Don't call the wrapped object if side_effect is set

When a object is wrapped using Mock(wraps=...), if an user sets a
side_effect in one of their methods, return the value of side_effect
and don't call the original object.

  • Refactor what to be called on mock_call

When a Mock is called, it should return looking up in the following
order: side_effect, return_value, wraps. If any of the first two
return mock.DEFAULT, lookup in the next option.

It makes no sense to check for wraps returning default, as it is
supposed to be the original implementation and there is nothing to
fallback to.
(cherry picked from commit f05df0a)

Co-authored-by: Mario Corchero [email protected]

https://bugs.python.org/issue35330

…0973)

* tests: Further validate `wraps` functionality in `unittest.mock.Mock`

Add more tests to validate how `wraps` interacts with other features of
mocks.

* Don't call the wrapped object if `side_effect` is set

When a object is wrapped using `Mock(wraps=...)`, if an user sets a
`side_effect` in one of their methods, return the value of `side_effect`
and don't call the original object.

* Refactor what to be called on `mock_call`

When a `Mock` is called, it should return looking up in the following
order: `side_effect`, `return_value`, `wraps`. If any of the first two
return `mock.DEFAULT`, lookup in the next option.

It makes no sense to check for `wraps` returning default, as it is
supposed to be the original implementation and there is nothing to
fallback to.
(cherry picked from commit f05df0a)

Co-authored-by: Mario Corchero <[email protected]>
@miss-islington
Copy link
Contributor Author

@mariocj89 and @cjw296: Status check is done, and it's a success ✅ .

@cjw296 cjw296 merged commit 12b9fb6 into python:3.6 Dec 8, 2018
@miss-islington miss-islington deleted the backport-f05df0a-3.6 branch December 8, 2018 11:41
@miss-islington
Copy link
Contributor Author

@mariocj89 and @cjw296: Status check is done, and it's a success ✅ .

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