bpo-25597: Ensure wraps' return value is used for magic methods in MagicMock (#16029)

This commit is contained in:
Karthikeyan Singaravelan 2020-01-27 12:18:15 +05:30 committed by Chris Withers
parent 10355ed7f1
commit 72b1004657
3 changed files with 56 additions and 0 deletions

View file

@ -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