[issue17826] Setting a side_effect on mock from create_autospec doesn't work

Michael Foord report at bugs.python.org
Fri Apr 26 13:35:13 CEST 2013


Michael Foord added the comment:

This illustrates the difference:

>>> from mock import Mock, create_autospec
>>> some_list = [1, 2, 3]
>>> m = Mock()
>>> m.side_effect = some_list
>>> m.side_effect
<listiterator object at 0x1004ab7d0>
>>> m2 = create_autospec(lambda: None)
>>> m2.side_effect = some_list
>>> m2.side_effect
[1, 2, 3]


When setting a side_effect on a function (created by create_autospec) the side_effect setter is not used - so turning the list into an iterator needs to be done on first use instead.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17826>
_______________________________________


More information about the Python-bugs-list mailing list