Skip to content

Commit 0c9efd5

Browse files
author
Sylvain MARIE
committed
Fixed ValueError issue happening with indirectly parametrized fixtures. Fixed #64
1 parent 791a547 commit 0c9efd5

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pytest_cases/plugin.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,10 @@ def getfixtureclosure(fm, fixturenames, parentnode, ignore_args=()):
510510

511511
sorted_fixturenames = sort_according_to_ref_list(fixturenames, param_names)
512512
# **********
513+
# merge the fixture names in correct order into the _init_fixnames
513514
merge(sorted_fixturenames, _init_fixnames)
514515
else:
515-
# we cannot sort yet
516+
# we cannot sort yet - merge the fixture names into the _init_fixnames
516517
merge(fixturenames, _init_fixnames)
517518
sorted_fixturenames = []
518519

@@ -976,7 +977,12 @@ def sort_according_to_ref_list(fixturenames, param_names):
976977
"""
977978
cur_indices = []
978979
for pname in param_names:
979-
cur_indices.append(fixturenames.index(pname))
980+
try:
981+
cur_indices.append(fixturenames.index(pname))
982+
except (ValueError, IndexError):
983+
# can happen in case of indirect parametrization: a parameter is not in the fixture name.
984+
# TODO we should maybe rather add the pname to fixturenames in this case ?
985+
pass
980986
target_indices = sorted(cur_indices)
981987
sorted_fixturenames = list(fixturenames)
982988
for old_i, new_i in zip(cur_indices, target_indices):
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
3+
4+
@pytest.fixture
5+
def my_fixture(request):
6+
return request.param
7+
8+
9+
@pytest.fixture
10+
def dependent_fixture(my_fixture):
11+
return my_fixture * 2
12+
13+
14+
@pytest.mark.parametrize('my_fixture', [123], indirect=True)
15+
def test_x(dependent_fixture):
16+
assert dependent_fixture == 2 * 123
17+

0 commit comments

Comments
 (0)