Skip to content

Commit 4198d76

Browse files
author
Sylvain MARIE
committed
Fixed @pytest_fixture_plus in case it is used with parametrize and one parameter is itself customized using pytest.param. Fixed #29
1 parent 4c095e5 commit 4198d76

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

pytest_cases/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,14 @@ def pytest_fixture_plus(scope="function",
295295
if is_marked_parameter_value(v):
296296
marks = get_marked_parameter_marks(v)
297297
vals = get_marked_parameter_values(v)
298-
if len(vals) != 1:
298+
if len(vals) != len(_pnames):
299299
raise ValueError("Internal error - unsupported pytest parametrization+mark combination. Please "
300300
"report this issue")
301301
_pmarks.append(marks) # there might be several
302-
_pvalues.append(vals[0])
302+
if len(vals) == 1:
303+
_pvalues.append(vals[0])
304+
else:
305+
_pvalues.append(vals)
303306
else:
304307
_pmarks.append(None)
305308
_pvalues.append(v)

pytest_cases/tests/simple/test_fixtures_params.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
from distutils.version import LooseVersion
2+
13
from pytest_cases import pytest_fixture_plus
24
import pytest
35

6+
# pytest.param - not available in all versions
7+
if LooseVersion(pytest.__version__) >= LooseVersion('3.0.0'):
8+
pytest_param = pytest.param
9+
else:
10+
def pytest_param(*args):
11+
return args
12+
413

514
@pytest_fixture_plus(scope="module")
615
@pytest.mark.parametrize("arg1", ["one", "two"])
@@ -18,7 +27,7 @@ def test_one(myfix):
1827
@pytest_fixture_plus
1928
@pytest.mark.parametrize("arg1, arg2", [
2029
(1, 2),
21-
(3, 4),
30+
pytest_param(3, 4),
2231
])
2332
def myfix2(arg1, arg2):
2433
return arg1, arg2

0 commit comments

Comments
 (0)