Author mrh1997
Recipients mrh1997
Date 2018-04-06.11:50:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
According to the documentation .return_value should be identical to the object returned when calling the mock ("assert m() is m.return_value")

This is the case except on objects returned by __iter__ on MagicMocks. The following script demonstrates the problem:
from unittest.mock import MagicMock
m = MagicMock()
assert x.__iter__() is x.__iter__.return_value    # <- fails

In fact __iter__() returns the object "iter([])" (which matches the documentation) while __iter__.return_value return a MagicMock object (which does not match the documentation).

When replacing "__iter__" with any other special function MagicMock works as expected.
Date User Action Args
2018-04-06 11:50:07mrh1997setrecipients: + mrh1997
2018-04-06 11:50:07mrh1997setmessageid: <>
2018-04-06 11:50:07mrh1997linkissue33236 messages
2018-04-06 11:50:07mrh1997create