Author xtreak
Recipients Darragh Bailey, anthonypjshaw, aviso, cjw296, lisroach, mariocj89, michael.foord, pconnell, r.david.murray, rbcollins, xtreak
Date 2020-03-15.08:57:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1584262663.74.0.759450270062.issue39966@roundup.psfhosted.org>
In-reply-to
Content
Thanks for the report. There should be a check to ensure that the attribute is present to handle the attribute error while attaching the wrapped object's value. Something like below could be done so that we check for wrapped value or fallback to the old behaviour. This needs a test too where the report can be added as a unittest. The news entry can also ensure that the wrapped value will be used when present or falls back to the default value. Marking it as a 3.9 regression.

diff --git Lib/unittest/mock.py Lib/unittest/mock.py
index 20daf724c1..86e832cc51 100644
--- Lib/unittest/mock.py
+++ Lib/unittest/mock.py
@@ -2036,7 +2036,7 @@ _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:
+    if mock._mock_wraps is not None and hasattr(mock._mock_wraps, name):
         method._mock_wraps = getattr(mock._mock_wraps, name)
         return
History
Date User Action Args
2020-03-15 08:57:43xtreaksetrecipients: + xtreak, rbcollins, cjw296, r.david.murray, michael.foord, pconnell, Darragh Bailey, lisroach, anthonypjshaw, mariocj89, aviso
2020-03-15 08:57:43xtreaksetmessageid: <1584262663.74.0.759450270062.issue39966@roundup.psfhosted.org>
2020-03-15 08:57:43xtreaklinkissue39966 messages
2020-03-15 08:57:42xtreakcreate