2121from _pytest import python
2222from _pytest .compat import getfuncargnames
2323from _pytest .compat import NOTSET
24+ from _pytest .mark import ParameterSet
2425from _pytest .outcomes import fail
2526from _pytest .pytester import Pytester
2627from _pytest .python import Function
2728from _pytest .python import IdMaker
29+ from _pytest .python import resolve_values_indices_in_parametersets
2830from _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
16991717class TestMetafuncFunctionalAuto :
17001718 """Tests related to automatically find out the correct scope for
0 commit comments