Skip to content

Document and test stacking of parametrize. #892

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

Merged
merged 1 commit into from
Jul 27, 2015
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions doc/en/parametrize.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ Let's run this::
The one parameter set which caused a failure previously now
shows up as an "xfailed (expected to fail)" test.

To get all combinations of multiple parametrized arguments you can stack
``parametrize`` decorators::

import pytest
@pytest.mark.parametrize("x", [0, 1])
@pytest.mark.parametrize("y", [2, 3])
def test_foo(x, y):
pass

This will run the test with the arguments set to x=0/y=2, x=0/y=3, x=1/y=2 and
x=1/y=3.

.. note::

In versions prior to 2.4 one needed to specify the argument
Expand Down
14 changes: 14 additions & 0 deletions testing/python/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,20 @@ def pytest_pyfunc_call(self, pyfuncitem):
config.pluginmanager.register(MyPlugin2())
config.hook.pytest_pyfunc_call(pyfuncitem=item)

def test_multiple_parametrize(self, testdir):
modcol = testdir.getmodulecol("""
import pytest
@pytest.mark.parametrize('x', [0, 1])
@pytest.mark.parametrize('y', [2, 3])
def test1(x, y):
pass
""")
colitems = modcol.collect()
assert colitems[0].name == 'test1[2-0]'
assert colitems[1].name == 'test1[2-1]'
assert colitems[2].name == 'test1[3-0]'
assert colitems[3].name == 'test1[3-1]'

def test_issue751_multiple_parametrize_with_ids(self, testdir):
modcol = testdir.getmodulecol("""
import pytest
Expand Down