Skip to content

Commit

Permalink
Fixed parametrization order when @pytest_fixture_plus is used with …
Browse files Browse the repository at this point in the history
…several `@pytest.mark.parametrize`. Fixed #22
  • Loading branch information
Sylvain MARIE committed Feb 1, 2019
1 parent 2a5298d commit 9d0396a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 4 additions & 2 deletions pytest_cases/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import sys
from abc import abstractmethod, ABCMeta
from collections import OrderedDict
from distutils.version import LooseVersion
from inspect import getmembers, isgeneratorfunction, getmodule

Expand Down Expand Up @@ -303,8 +304,9 @@ def decorate_pytest_fixture_plus(fixture_func,

# for each dependency create an associated "param" fixture
# Note: we could instead have created a huge parameter containing all parameters...
# Pros = no additional fixture. Cons: less readable and ids would be difficult to create
params_map = dict()
# Pros = no additional fixture.
# Cons: less readable and ids would be difficult to create
params_map = OrderedDict()
for m in parametrizer_marks:
# check what the mark specifies in terms of parameters
if len(m.param_names) < 1:
Expand Down
15 changes: 11 additions & 4 deletions pytest_cases/tests/simple/test_stereo_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,18 @@ def assert_state_and_move(self, path, cfg_factory):
@pytest.mark.parametrize("cfg_factory", CFG_TYPES) # not actual params
def stereo_cfg(path, cfg_factory, request):
"""
A fixture with two parameters
A fixture with two parameters.
As opposed to `stereo_cfg_2`, we use here two @parametrize decorators.
We check that the execution order is correct.
"""
assert isinstance(path, str)
assert isinstance(cfg_factory, type)
a.assert_state_and_move(path=path, cfg_factory=cfg_factory)
return "hello"


def test_stereo(stereo_cfg):
def test_stereo_two_parametrizers(stereo_cfg):
"""
A test relying on a double-parametrized fixture.
See https://github.com/pytest-dev/pytest/issues/3960
Expand Down Expand Up @@ -82,7 +85,11 @@ def _id(x):
@pytest.mark.parametrize("cfg_factory,path", product(CFG_TYPES, STEREO_PATHS), ids=_id)
def stereo_cfg_2(path, request, cfg_factory):
"""
A fixture with two parameters
A fixture with two parameters.
As opposed to `stereo_cfg_1`, the order of the parameter is precomputed beforehand in
`product(CFG_TYPES, STEREO_PATHS)` and a single call to parametrize is made.
We check that the execution order is the same.
"""
assert isinstance(path, str)
assert isinstance(cfg_factory, type)
Expand All @@ -92,7 +99,7 @@ def stereo_cfg_2(path, request, cfg_factory):
yield "hello"


def test_stereo_2(stereo_cfg_2):
def test_stereo_one_global_parametrizer(stereo_cfg_2):
pass


Expand Down

0 comments on commit 9d0396a

Please sign in to comment.