From 70ca7540f17bcd075954bf9cd71dbe546b6495d0 Mon Sep 17 00:00:00 2001 From: Sadra Barikbin Date: Sun, 17 Dec 2023 14:06:34 +0330 Subject: [PATCH] Add a test --- testing/python/metafunc.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index bf1157e8a..7ef98ca75 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -21,10 +21,12 @@ from _pytest import fixtures from _pytest import python from _pytest.compat import getfuncargnames from _pytest.compat import NOTSET +from _pytest.mark import ParameterSet from _pytest.outcomes import fail from _pytest.pytester import Pytester from _pytest.python import Function from _pytest.python import IdMaker +from _pytest.python import resolve_values_indices_in_parametersets from _pytest.scope import Scope @@ -984,6 +986,12 @@ class TestMetafunc: assert metafunc._calls[1].params == dict(x=3, y=4) assert metafunc._calls[1].id == "3-4" + def test_parametrize_with_duplicate_args(self) -> None: + metafunc = self.Metafunc(lambda x: None) + metafunc.parametrize("x", [0, 1]) + with pytest.raises(ValueError, match="duplicate 'x'"): + metafunc.parametrize("x", [2, 3]) + def test_parametrize_with_duplicate_values(self) -> None: metafunc = self.Metafunc(lambda x, y: None) metafunc.parametrize(("x", "y"), [(1, 2), (3, 4), (1, 5), (2, 2)]) @@ -995,7 +1003,7 @@ class TestMetafunc: def test_parametrize_with_unhashable_duplicate_values(self) -> None: metafunc = self.Metafunc(lambda x: None) - metafunc.parametrize(("x"), [[1], [2], [1]]) + metafunc.parametrize("x", [[1], [2], [1]]) assert len(metafunc._calls) == 3 assert metafunc._calls[0].indices == dict(x=0) assert metafunc._calls[1].indices == dict(x=1) @@ -1695,6 +1703,16 @@ class TestMetafuncFunctional: ] ) + def test_resolve_values_indices_in_parametersets(self, pytester: Pytester) -> None: + indices = resolve_values_indices_in_parametersets( + ("a", "b"), + [ + ParameterSet.extract_from((a, b)) + for a, b in [(1, 1), (1, 2), (2, 3), ([2], 4), ([2], 1)] + ], + ) + assert indices == [(0, 0), (0, 1), (1, 2), (2, 3), (3, 0)] + class TestMetafuncFunctionalAuto: """Tests related to automatically find out the correct scope for