From 0b6028f748a284766367b5f62514ddece3dbe1cc Mon Sep 17 00:00:00 2001 From: Aleksandr Brodin Date: Wed, 6 Mar 2024 15:20:25 +0700 Subject: [PATCH 1/2] change param_index for pseudofixturedef --- src/_pytest/python.py | 4 +++- testing/python/metafunc.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index e1730b1a7e0..3353e2e12ee 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -1326,10 +1326,12 @@ def parametrize( # more than once) then we accumulate those calls generating the cartesian product # of all calls. newcalls = [] - for callspec in self._calls or [CallSpec2()]: + for callspec_index, callspec in enumerate(self._calls or [CallSpec2()]): for param_index, (param_id, param_set) in enumerate( zip(ids, parametersets) ): + if name2pseudofixturedef: + param_index = callspec_index + param_index newcallspec = callspec.setmulti( argnames=argnames, valset=param_set.values, diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index ed22c2b5a1c..474852be1d4 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -1019,6 +1019,35 @@ def test3(arg1): ] ) + def test_multi_parametrize_reordering(self, pytester: Pytester) -> None: + pytester.makepyfile( + """ + import pytest + + @pytest.mark.parametrize("arg2", ['a', 'b'], scope='class') + @pytest.mark.parametrize("arg1", [1, 2], scope='class') + class TestClass: + def test1(self, arg1, arg2): + pass + + def test2(self, arg1, arg2): + pass + """ + ) + result = pytester.runpytest("--collect-only") + result.stdout.re_match_lines( + [ + r" ", + r" ", + r" ", + r" ", + r" ", + r" ", + r" ", + r" ", + ] + ) + def test_parametrize_multiple_times(self, pytester: Pytester) -> None: pytester.makepyfile( """ From 2718e9bced80e4f772fc112b0243f752d370a689 Mon Sep 17 00:00:00 2001 From: Aleksandr Brodin Date: Sun, 24 Mar 2024 14:36:13 +0700 Subject: [PATCH 2/2] same param_index usage for markers params and fixtures params --- src/_pytest/python.py | 3 +-- testing/python/fixtures.py | 8 ++++---- testing/python/metafunc.py | 6 +++++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 3353e2e12ee..12478d17992 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -1330,8 +1330,7 @@ def parametrize( for param_index, (param_id, param_set) in enumerate( zip(ids, parametersets) ): - if name2pseudofixturedef: - param_index = callspec_index + param_index + param_index = callspec_index * len(parametersets) + param_index newcallspec = callspec.setmulti( argnames=argnames, valset=param_set.values, diff --git a/testing/python/fixtures.py b/testing/python/fixtures.py index 6edff6ecd43..cf402f30ccb 100644 --- a/testing/python/fixtures.py +++ b/testing/python/fixtures.py @@ -2690,12 +2690,12 @@ def test_func4(marg): test_mod2.py::test_func2[s2] PASSED test_mod2.py::test_func3[s2-m1] PASSED test_mod2.py::test_func3b[s2-m1] PASSED - test_mod2.py::test_func4[m1] PASSED test_mod2.py::test_func3[s2-m2] PASSED test_mod2.py::test_func3b[s2-m2] PASSED - test_mod2.py::test_func4[m2] PASSED test_mod1.py::test_func1[m1] PASSED test_mod1.py::test_func1[m2] PASSED + test_mod2.py::test_func4[m1] PASSED + test_mod2.py::test_func4[m2] PASSED """ ) @@ -2741,10 +2741,10 @@ def test2(reprovision): test_dynamic_parametrized_ordering.py::test2[flavor1-vxlan] PASSED test_dynamic_parametrized_ordering.py::test[flavor1-vlan] PASSED test_dynamic_parametrized_ordering.py::test2[flavor1-vlan] PASSED - test_dynamic_parametrized_ordering.py::test[flavor2-vlan] PASSED - test_dynamic_parametrized_ordering.py::test2[flavor2-vlan] PASSED test_dynamic_parametrized_ordering.py::test[flavor2-vxlan] PASSED test_dynamic_parametrized_ordering.py::test2[flavor2-vxlan] PASSED + test_dynamic_parametrized_ordering.py::test[flavor2-vlan] PASSED + test_dynamic_parametrized_ordering.py::test2[flavor2-vlan] PASSED """ ) diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 474852be1d4..49361e2e779 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -1024,7 +1024,7 @@ def test_multi_parametrize_reordering(self, pytester: Pytester) -> None: """ import pytest - @pytest.mark.parametrize("arg2", ['a', 'b'], scope='class') + @pytest.mark.parametrize("arg2", ['a', 'b', 'c'], scope='class') @pytest.mark.parametrize("arg1", [1, 2], scope='class') class TestClass: def test1(self, arg1, arg2): @@ -1041,10 +1041,14 @@ def test2(self, arg1, arg2): r" ", r" ", r" ", + r" ", + r" ", r" ", r" ", r" ", r" ", + r" ", + r" ", ] )