Karthikeyan Singaravelan <tir.kar...@gmail.com> added the comment:

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

----------
keywords: +3.9regression

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39966>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to