summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/mock.py
diff options
context:
space:
mode:
authorKarthikeyan Singaravelan <tir.karthi@gmail.com>2020-01-27 06:48:15 (GMT)
committerChris Withers <chris@withers.org>2020-01-27 06:48:15 (GMT)
commit72b1004657e60c900e4cd031b2635b587f4b280e (patch)
tree42083b97c64d233476d1451d9a6375567e8fb7c3 /Lib/unittest/mock.py
parent10355ed7f132ed10f1e0d8bd64ccb744b86b1cce (diff)
downloadcpython-72b1004657e60c900e4cd031b2635b587f4b280e.zip
cpython-72b1004657e60c900e4cd031b2635b587f4b280e.tar.gz
cpython-72b1004657e60c900e4cd031b2635b587f4b280e.tar.bz2
bpo-25597: Ensure wraps' return value is used for magic methods in MagicMock (#16029)
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r--Lib/unittest/mock.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index beed717..1acafc5 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -2033,6 +2033,12 @@ _side_effect_methods = {
def _set_return_value(mock, method, name):
+ # If _mock_wraps is present then attach it so that wrapped object
+ # is used for return value is used when called.
+ if mock._mock_wraps is not None:
+ method._mock_wraps = getattr(mock._mock_wraps, name)
+ return
+
fixed = _return_values.get(name, DEFAULT)
if fixed is not DEFAULT:
method.return_value = fixed