Skip to content

Commit 3bdb1f4

Browse files
author
Sylvain MARIE
committed
Fixed "Created fixture names are not unique, please report" error when duplicate fixture reference is provided in a pytest.param. Fixes #138
1 parent 5e4b125 commit 3bdb1f4

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

pytest_cases/fixture_parametrize_plus.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from .common_pytest_marks import has_pytest_param, get_param_argnames_as_list
2727
from .common_pytest_lazy_values import is_lazy_value, is_lazy, get_lazy_args
2828
from .common_pytest import get_fixture_name, remove_duplicates, mini_idvalset, is_marked_parameter_value, \
29-
extract_parameterset_info, ParameterSet, cart_product_pytest, mini_idval, inject_host
29+
extract_parameterset_info, ParameterSet, cart_product_pytest, mini_idval, inject_host, get_marked_parameter_values
3030

3131
from .fixture__creation import check_name_available, CHANGE, WARN
3232
from .fixture_core1_unions import InvalidParamsList, NOT_USED, UnionFixtureAlternative, _make_fixture_union, \
@@ -698,6 +698,10 @@ def parametrize_plus_decorate(test_func, fixtures_dest):
698698
fix_alt_names.append(a)
699699
else:
700700
# this should only happen when the alternative is directly a fixture reference
701+
if is_marked_parameter_value(alt):
702+
alt = get_marked_parameter_values(alt)
703+
assert len(alt) == 1, "Error with fixture reference, please report"
704+
alt = alt[0]
701705
assert isinstance(alt, FixtureParamAlternative), \
702706
"Created fixture names are not unique, please report"
703707

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pytest
2+
from pytest_cases import fixture, parametrize, fixture_ref
3+
4+
5+
@fixture
6+
def b():
7+
print("b")
8+
return "b"
9+
10+
11+
@parametrize("fixture", [fixture_ref(b),
12+
pytest.param(fixture_ref(b))
13+
])
14+
def test(fixture):
15+
assert fixture == "b"
16+
print("Test ran fixure %s" % fixture)
17+
18+
19+
@parametrize("fixture,a", [(fixture_ref(b), 1),
20+
pytest.param(fixture_ref(b), 1)
21+
])
22+
def test2(fixture, a):
23+
assert fixture == "b"
24+
assert a == 1
25+
print("Test ran fixure %s" % fixture)

0 commit comments

Comments
 (0)