New submission from Gregory Ronin <gregoryro...@yahoo.com>:

In mock.py, in method:
def _mock_call(_mock_self, *args, **kwargs):

There is a following piece of code:

    if not _callable(effect):
        result = next(effect)
        if _is_exception(result):
            raise result
        if result is DEFAULT:
            result = self.return_value
        return result

    ret_val = effect(*args, **kwargs)

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.

It seems like the check should be not for callable, but for iterable:

    try:
        iter(effect)
    except TypeError:
        # If not iterable then callable or exception
        if _callable(effect):
            ret_val = effect(*args, **kwargs)
        else:
            raise effect

    else:  # Iterable
        result = next(effect)
        if _is_exception(result):
            raise result
        if result is DEFAULT:
            result = self.return_value
        return result

----------
components: Tests
messages: 339923
nosy: jazzblue
priority: normal
severity: normal
status: open
title: mock side_effect should be checked for iterable not callable
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36598>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to