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 xtreak
Recipients jazzblue, xtreak
Date 2019-04-11.06:07:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1554962866.96.0.46550401377.issue36598@roundup.psfhosted.org>
In-reply-to
Content
I am not sure if the snippets you are referring to are from testing-cabal/mock repo which could be different from master branch. Current code is at [0]

if effect is not None:
    if _is_exception(effect):
        raise effect
    elif not _callable(effect):
        result = next(effect)
        if _is_exception(result):
            raise result
    else:
        result = effect(*args, **kwargs)

    if result is not DEFAULT:
        return result

> This works correctly for iterables (such as lists) that are not defined as generators.
However, if one defined a generator as a function this would not work.

This does seem to work for generator function as below. Sorry, maybe I am getting it wrong with respect to terminologies and understanding the issue. Can you add a short script around what you are expecting?

$ cat ../backups/bpo36598.py
from unittest.mock import patch

def gen(i):
    while i < 5:
        yield i
        i += 1

def foo():
    return 1

with patch('__main__.foo', side_effect=gen(0)):
    for _ in range(2):
        print(foo())
    for _ in range(2):
        print(foo())
$ ./python.exe ../backups/bpo36598.py
0
1
2
3

[0] https://github.com/python/cpython/blob/a9bd8925c7fa50dd3cfab125b824ec192133ef49/Lib/unittest/mock.py#L1043
History
Date User Action Args
2019-04-11 06:07:46xtreaksetrecipients: + xtreak, jazzblue
2019-04-11 06:07:46xtreaksetmessageid: <1554962866.96.0.46550401377.issue36598@roundup.psfhosted.org>
2019-04-11 06:07:46xtreaklinkissue36598 messages
2019-04-11 06:07:46xtreakcreate