Skip to content

Commit 9cf9900

Browse files
committed
Merge pull request pytest-dev#892 from The-Compiler/multi-parametrize
Document and test stacking of parametrize.
2 parents 2035c5f + 2ab4bf1 commit 9cf9900

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

doc/en/parametrize.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ Let's run this::
114114
The one parameter set which caused a failure previously now
115115
shows up as an "xfailed (expected to fail)" test.
116116

117+
To get all combinations of multiple parametrized arguments you can stack
118+
``parametrize`` decorators::
119+
120+
import pytest
121+
@pytest.mark.parametrize("x", [0, 1])
122+
@pytest.mark.parametrize("y", [2, 3])
123+
def test_foo(x, y):
124+
pass
125+
126+
This will run the test with the arguments set to x=0/y=2, x=0/y=3, x=1/y=2 and
127+
x=1/y=3.
128+
117129
.. note::
118130

119131
In versions prior to 2.4 one needed to specify the argument

testing/python/collect.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,20 @@ def pytest_pyfunc_call(self, pyfuncitem):
472472
config.pluginmanager.register(MyPlugin2())
473473
config.hook.pytest_pyfunc_call(pyfuncitem=item)
474474

475+
def test_multiple_parametrize(self, testdir):
476+
modcol = testdir.getmodulecol("""
477+
import pytest
478+
@pytest.mark.parametrize('x', [0, 1])
479+
@pytest.mark.parametrize('y', [2, 3])
480+
def test1(x, y):
481+
pass
482+
""")
483+
colitems = modcol.collect()
484+
assert colitems[0].name == 'test1[2-0]'
485+
assert colitems[1].name == 'test1[2-1]'
486+
assert colitems[2].name == 'test1[3-0]'
487+
assert colitems[3].name == 'test1[3-1]'
488+
475489
def test_issue751_multiple_parametrize_with_ids(self, testdir):
476490
modcol = testdir.getmodulecol("""
477491
import pytest

0 commit comments

Comments
 (0)