Staging
v0.5.1
https://github.com/python/cpython
Revision ee2c5a8e2dcf662048dbcf4e49af9b4aaf81f7d3 authored by Miss Islington (bot) on 08 December 2018, 11:47:01 UTC, committed by Chris Withers on 08 December 2018, 11:47:01 UTC
* 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 f05df0a4b679d0acfd0b1fe6187ba2d553b37afa)

Co-authored-by: Mario Corchero <mariocj89@gmail.com>
1 parent 783b794
History
Tip revision: ee2c5a8e2dcf662048dbcf4e49af9b4aaf81f7d3 authored by Miss Islington (bot) on 08 December 2018, 11:47:01 UTC
bpo-35330: Don't call the wrapped object if `side_effect` is set (GH11035)
Tip revision: ee2c5a8
File Mode Size
.azure-pipelines
.github
Doc
Grammar
Include
Lib
Mac
Misc
Modules
Objects
PC
PCbuild
Parser
Programs
Python
Tools
m4
.gitattributes -rw-r--r-- 1.5 KB
.gitignore -rw-r--r-- 1.5 KB
.travis.yml -rw-r--r-- 6.0 KB
CODE_OF_CONDUCT.rst -rw-r--r-- 631 bytes
LICENSE -rw-r--r-- 12.5 KB
Makefile.pre.in -rw-r--r-- 61.6 KB
README.rst -rw-r--r-- 9.9 KB
aclocal.m4 -rw-r--r-- 10.7 KB
config.guess -rwxr-xr-x 43.1 KB
config.sub -rwxr-xr-x 35.4 KB
configure -rwxr-xr-x 488.5 KB
configure.ac -rw-r--r-- 163.3 KB
install-sh -rwxr-xr-x 7.0 KB
pyconfig.h.in -rw-r--r-- 42.1 KB
setup.py -rw-r--r-- 99.5 KB

README.rst

back to top