Merge pull request #892 from The-Compiler/multi-parametrize

Document and test stacking of parametrize.
This commit is contained in:
Bruno Oliveira 2015-07-26 21:00:29 -03:00
commit 9cf9900721
2 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -472,6 +472,20 @@ class TestFunction:
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