[New-bugs-announce] [issue33236] MagicMock().__iter__.return_value is different from MagicMock().__iter__()
Robert
report at bugs.python.org
Fri Apr 6 07:50:07 EDT 2018
New submission from Robert <lma at 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 <report at bugs.python.org>
<https://bugs.python.org/issue33236>
_______________________________________
More information about the New-bugs-announce
mailing list