This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mjpieters
Recipients mjpieters
Date 2015-08-13.07:35:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1439451353.27.0.842295634164.issue24856@psf.upfronthosting.co.za>
In-reply-to
Content
The documentation states that `side_effect` can be set to an [iterable](https://docs.python.org/3/glossary.html#term-iterable):

> If you pass in an iterable, it is used to retrieve an iterator which must yield a value on every call. This value can either be an exception instance to be raised, or a value to be returned from the call to the mock (`DEFAULT` handling is identical to the function case).

but the [actual handling of the side effect](https://github.com/testing-cabal/mock/blob/27a20329b25c8de200a8964ed5dd7762322e91f6/mock/mock.py#L1112-L1123) expects it to be an [*iterator*](https://docs.python.org/3/glossary.html#term-iterator):

if not _callable(effect):
    result = next(effect)

This excludes using a list or tuple object to produce the side effect sequence.

Can the documentation be updated to state an *iterator* is required (so an object that defines __next__ and who's __iter__ method returns self), or can the CallableMixin constructor be updated to call iter() on the side_effect argument if it is not an exception or a callable? You could even re-use the [_MockIter() class](https://hg.python.org/cpython/file/256d2f01e975/Lib/unittest/mock.py#l348) already used for the [NonCallableMock.side_effect property](https://hg.python.org/cpython/file/256d2f01e975/Lib/unittest/mock.py#l509).
History
Date User Action Args
2015-08-13 07:35:53mjpieterssetrecipients: + mjpieters
2015-08-13 07:35:53mjpieterssetmessageid: <1439451353.27.0.842295634164.issue24856@psf.upfronthosting.co.za>
2015-08-13 07:35:53mjpieterslinkissue24856 messages
2015-08-13 07:35:52mjpieterscreate