New submission from Robert <l...@posteo.de>: 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. ---------- components: Library (Lib) messages: 315016 nosy: mrh1997 priority: normal severity: normal status: open title: MagicMock().__iter__.return_value is different from MagicMock().__iter__() versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33236> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com