Skip to content

Commit 70ca754

Browse files
Add a test
1 parent 30d3231 commit 70ca754

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

testing/python/metafunc.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
from _pytest import python
2222
from _pytest.compat import getfuncargnames
2323
from _pytest.compat import NOTSET
24+
from _pytest.mark import ParameterSet
2425
from _pytest.outcomes import fail
2526
from _pytest.pytester import Pytester
2627
from _pytest.python import Function
2728
from _pytest.python import IdMaker
29+
from _pytest.python import resolve_values_indices_in_parametersets
2830
from _pytest.scope import Scope
2931

3032

@@ -984,6 +986,12 @@ def test_parametrize_twoargs(self) -> None:
984986
assert metafunc._calls[1].params == dict(x=3, y=4)
985987
assert metafunc._calls[1].id == "3-4"
986988

989+
def test_parametrize_with_duplicate_args(self) -> None:
990+
metafunc = self.Metafunc(lambda x: None)
991+
metafunc.parametrize("x", [0, 1])
992+
with pytest.raises(ValueError, match="duplicate 'x'"):
993+
metafunc.parametrize("x", [2, 3])
994+
987995
def test_parametrize_with_duplicate_values(self) -> None:
988996
metafunc = self.Metafunc(lambda x, y: None)
989997
metafunc.parametrize(("x", "y"), [(1, 2), (3, 4), (1, 5), (2, 2)])
@@ -995,7 +1003,7 @@ def test_parametrize_with_duplicate_values(self) -> None:
9951003

9961004
def test_parametrize_with_unhashable_duplicate_values(self) -> None:
9971005
metafunc = self.Metafunc(lambda x: None)
998-
metafunc.parametrize(("x"), [[1], [2], [1]])
1006+
metafunc.parametrize("x", [[1], [2], [1]])
9991007
assert len(metafunc._calls) == 3
10001008
assert metafunc._calls[0].indices == dict(x=0)
10011009
assert metafunc._calls[1].indices == dict(x=1)
@@ -1695,6 +1703,16 @@ def test_3(self, fixture):
16951703
]
16961704
)
16971705

1706+
def test_resolve_values_indices_in_parametersets(self, pytester: Pytester) -> None:
1707+
indices = resolve_values_indices_in_parametersets(
1708+
("a", "b"),
1709+
[
1710+
ParameterSet.extract_from((a, b))
1711+
for a, b in [(1, 1), (1, 2), (2, 3), ([2], 4), ([2], 1)]
1712+
],
1713+
)
1714+
assert indices == [(0, 0), (0, 1), (1, 2), (2, 3), (3, 0)]
1715+
16981716

16991717
class TestMetafuncFunctionalAuto:
17001718
"""Tests related to automatically find out the correct scope for

0 commit comments

Comments
 (0)