Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change param_index if param is pseudofixturedef #12082

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,10 +1326,11 @@ 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)
):
param_index = callspec_index * len(parametersets) + param_index
newcallspec = callspec.setmulti(
argnames=argnames,
valset=param_set.values,
Expand Down
8 changes: 4 additions & 4 deletions testing/python/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
)

Expand Down Expand Up @@ -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
"""
)

Expand Down
33 changes: 33 additions & 0 deletions testing/python/metafunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,39 @@ def test3(arg1):
]
)

def test_multi_parametrize_reordering(self, pytester: Pytester) -> None:
pytester.makepyfile(
"""
import pytest

@pytest.mark.parametrize("arg2", ['a', 'b', 'c'], 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" <Function test1\[1-a\]>",
r" <Function test2\[1-a\]>",
r" <Function test1\[1-b\]>",
r" <Function test2\[1-b\]>",
r" <Function test1\[1-c\]>",
r" <Function test2\[1-c\]>",
r" <Function test1\[2-a\]>",
r" <Function test2\[2-a\]>",
r" <Function test1\[2-b\]>",
r" <Function test2\[2-b\]>",
r" <Function test1\[2-c\]>",
r" <Function test2\[2-c\]>",
]
)

def test_parametrize_multiple_times(self, pytester: Pytester) -> None:
pytester.makepyfile(
"""
Expand Down
Loading