Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of iterator in non-parameterized decorator #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,27 @@ into memory before the start of the test run (we do this explicitly to ensure
that generators are exhausted exactly once in multi-process or multi-threaded
testing environments).

This also applies to iterators or generators in other decorators. For example,
the following works for the first run but not the second:

.. code:: python

@parameterized.expand([('first run',), ('second run',)])
@mock.patch.object(MyIterator, 'get_iterator', new=mock.Mock(
return_value=iter([1])))
def test_foo(self, bar):
...

Workaround:

.. code:: python

@parameterized.expand([('first run',), ('second run',)])
@mock.patch.object(MyIterator, 'get_iterator')
def test_foo(self, bar, mock_get_iterator):
mock_get_iterator.return_value = iter([1])
...

The ``@parameterized`` decorator can be used test class methods, and standalone
functions:

Expand Down