Skip to content

Commit 9d0396a

Browse files
author
Sylvain MARIE
committed
Fixed parametrization order when @pytest_fixture_plus is used with several @pytest.mark.parametrize. Fixed #22
1 parent 2a5298d commit 9d0396a

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

pytest_cases/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import sys
55
from abc import abstractmethod, ABCMeta
6+
from collections import OrderedDict
67
from distutils.version import LooseVersion
78
from inspect import getmembers, isgeneratorfunction, getmodule
89

@@ -303,8 +304,9 @@ def decorate_pytest_fixture_plus(fixture_func,
303304

304305
# for each dependency create an associated "param" fixture
305306
# Note: we could instead have created a huge parameter containing all parameters...
306-
# Pros = no additional fixture. Cons: less readable and ids would be difficult to create
307-
params_map = dict()
307+
# Pros = no additional fixture.
308+
# Cons: less readable and ids would be difficult to create
309+
params_map = OrderedDict()
308310
for m in parametrizer_marks:
309311
# check what the mark specifies in terms of parameters
310312
if len(m.param_names) < 1:

pytest_cases/tests/simple/test_stereo_fixtures.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@ def assert_state_and_move(self, path, cfg_factory):
4040
@pytest.mark.parametrize("cfg_factory", CFG_TYPES) # not actual params
4141
def stereo_cfg(path, cfg_factory, request):
4242
"""
43-
A fixture with two parameters
43+
A fixture with two parameters.
44+
45+
As opposed to `stereo_cfg_2`, we use here two @parametrize decorators.
46+
We check that the execution order is correct.
4447
"""
4548
assert isinstance(path, str)
4649
assert isinstance(cfg_factory, type)
4750
a.assert_state_and_move(path=path, cfg_factory=cfg_factory)
4851
return "hello"
4952

5053

51-
def test_stereo(stereo_cfg):
54+
def test_stereo_two_parametrizers(stereo_cfg):
5255
"""
5356
A test relying on a double-parametrized fixture.
5457
See https://github.com/pytest-dev/pytest/issues/3960
@@ -82,7 +85,11 @@ def _id(x):
8285
@pytest.mark.parametrize("cfg_factory,path", product(CFG_TYPES, STEREO_PATHS), ids=_id)
8386
def stereo_cfg_2(path, request, cfg_factory):
8487
"""
85-
A fixture with two parameters
88+
A fixture with two parameters.
89+
90+
As opposed to `stereo_cfg_1`, the order of the parameter is precomputed beforehand in
91+
`product(CFG_TYPES, STEREO_PATHS)` and a single call to parametrize is made.
92+
We check that the execution order is the same.
8693
"""
8794
assert isinstance(path, str)
8895
assert isinstance(cfg_factory, type)
@@ -92,7 +99,7 @@ def stereo_cfg_2(path, request, cfg_factory):
9299
yield "hello"
93100

94101

95-
def test_stereo_2(stereo_cfg_2):
102+
def test_stereo_one_global_parametrizer(stereo_cfg_2):
96103
pass
97104

98105

0 commit comments

Comments
 (0)