Skip to content

Commit 2a805ed

Browse files
author
Sylvain MARIE
committed
Added test for the error with pytest 2, and improve readability of the section raising it
1 parent 8b95dcf commit 2a805ed

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

pytest_cases/common.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,15 @@ def get_pytest_parametrize_marks(f):
232232
# mark_info.args contains a list of (name, values)
233233
if len(mark_info.args) % 2 != 0:
234234
raise ValueError("internal pytest compatibility error - please report")
235-
nb_parameters = len(mark_info.args) // 2
236-
if nb_parameters > 1 and len(mark_info.kwargs) > 0:
235+
nb_parametrize_decorations = len(mark_info.args) // 2
236+
if nb_parametrize_decorations > 1 and len(mark_info.kwargs) > 0:
237237
raise ValueError("Unfortunately with this old pytest version it is not possible to have several "
238-
"parametrization decorators")
238+
"parametrization decorators while specifying **kwargs, as all **kwargs are "
239+
"merged, leading to inconsistent results. Either upgrade pytest, remove the **kwargs,"
240+
"or merge all the @parametrize decorators into a single one. **kwargs: %s"
241+
% mark_info.kwargs)
239242
res = []
240-
for i in range(nb_parameters):
243+
for i in range(nb_parametrize_decorations):
241244
param_name, param_values = mark_info.args[2*i:2*(i+1)]
242245
res.append(_ParametrizationMark(_LegacyMark(param_name, param_values, **mark_info.kwargs)))
243246
return tuple(res)

pytest_cases/tests/fixtures/test_fixtures_parametrize.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,22 @@ def test_synthesis(module_results_dct):
2727

2828

2929
# pytest.param - not available in all versions
30-
if LooseVersion(pytest.__version__) >= LooseVersion('3.0.0'):
30+
if LooseVersion(pytest.__version__) < LooseVersion('3.2.0'):
3131
# with pytest < 3.2.0 we
3232
# - would have to merge all parametrize marks if we wish to pass a kwarg (here, ids)
3333
# - cannot use pytest.param as it is not taken into account
3434
# > no go
3535

36+
def test_warning_pytest2():
37+
with pytest.raises(ValueError) as exc_info:
38+
@pytest_fixture_plus
39+
@pytest.mark.parametrize("arg2", [0], ids=str)
40+
@pytest.mark.parametrize("arg1", [1])
41+
def a(arg1, arg2):
42+
return arg1, arg2
43+
assert "Unfortunately with this old pytest version it" in str(exc_info.value)
44+
45+
else:
3646
@pytest_fixture_plus
3747
@pytest.mark.parametrize("arg3", [pytest.param(0, id='!0!')], ids=str)
3848
@pytest.mark.parametrize("arg1, arg2", [

0 commit comments

Comments
 (0)