Skip to content

Commit 6a3ac51

Browse files
Revert the unintended change in tests reordering from #11220 (#12542)
In #11220, an unintended change in reordering was introduced by changing the way indices were assigned to direct params. This PR reverts that change and reduces #11220 changes to just refactors. After this PR we could safely decide on the solutions discussed in #12008, i.e. #12082 or the one initially introduced in #11220 . Fixes #12008 Co-authored-by: Bruno Oliveira <[email protected]> Co-authored-by: Bruno Oliveira <[email protected]>
1 parent cb98538 commit 6a3ac51

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

changelog/12008.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In :pr:`11220`, an unintended change in reordering was introduced by changing the way indices were assigned to direct params. More specifically, before that change, the indices of direct params to metafunc's callspecs were assigned after all parametrizations took place. Now, that change is reverted.

src/_pytest/python.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ def _genfunctions(self, name: str, funcobj) -> Iterator[Function]:
464464
if not metafunc._calls:
465465
yield Function.from_parent(self, name=name, fixtureinfo=fixtureinfo)
466466
else:
467+
metafunc._recompute_direct_params_indices()
467468
# Direct parametrizations taking place in module/class-specific
468469
# `metafunc.parametrize` calls may have shadowed some fixtures, so make sure
469470
# we update what the function really needs a.k.a its fixture closure. Note that
@@ -1131,6 +1132,8 @@ def __init__(
11311132
# Result of parametrize().
11321133
self._calls: list[CallSpec2] = []
11331134

1135+
self._params_directness: dict[str, Literal["indirect", "direct"]] = {}
1136+
11341137
def parametrize(
11351138
self,
11361139
argnames: str | Sequence[str],
@@ -1273,6 +1276,7 @@ def parametrize(
12731276
name2pseudofixturedef_key, default
12741277
)
12751278
arg_directness = self._resolve_args_directness(argnames, indirect)
1279+
self._params_directness.update(arg_directness)
12761280
for argname in argnames:
12771281
if arg_directness[argname] == "indirect":
12781282
continue
@@ -1445,6 +1449,12 @@ def _validate_if_using_arg_names(
14451449
pytrace=False,
14461450
)
14471451

1452+
def _recompute_direct_params_indices(self) -> None:
1453+
for argname, param_type in self._params_directness.items():
1454+
if param_type == "direct":
1455+
for i, callspec in enumerate(self._calls):
1456+
callspec.indices[argname] = i
1457+
14481458

14491459
def _find_parametrized_scope(
14501460
argnames: Sequence[str],

testing/example_scripts/issue_519.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ def checked_order():
2323
assert order == [
2424
("issue_519.py", "fix1", "arg1v1"),
2525
("test_one[arg1v1-arg2v1]", "fix2", "arg2v1"),
26-
("test_one[arg1v1-arg2v2]", "fix2", "arg2v2"),
2726
("test_two[arg1v1-arg2v1]", "fix2", "arg2v1"),
27+
("test_one[arg1v1-arg2v2]", "fix2", "arg2v2"),
2828
("test_two[arg1v1-arg2v2]", "fix2", "arg2v2"),
2929
("issue_519.py", "fix1", "arg1v2"),
3030
("test_one[arg1v2-arg2v1]", "fix2", "arg2v1"),
31-
("test_one[arg1v2-arg2v2]", "fix2", "arg2v2"),
3231
("test_two[arg1v2-arg2v1]", "fix2", "arg2v1"),
32+
("test_one[arg1v2-arg2v2]", "fix2", "arg2v2"),
3333
("test_two[arg1v2-arg2v2]", "fix2", "arg2v2"),
3434
]
3535

testing/python/metafunc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,14 +1005,14 @@ def test3(arg1):
10051005
result.stdout.re_match_lines(
10061006
[
10071007
r" <Function test1\[0-3\]>",
1008-
r" <Function test1\[0-4\]>",
10091008
r" <Function test3\[0\]>",
1009+
r" <Function test1\[0-4\]>",
1010+
r" <Function test3\[1\]>",
10101011
r" <Function test1\[1-3\]>",
1012+
r" <Function test3\[2\]>",
10111013
r" <Function test1\[1-4\]>",
1012-
r" <Function test3\[1\]>",
10131014
r" <Function test1\[2-3\]>",
10141015
r" <Function test1\[2-4\]>",
1015-
r" <Function test3\[2\]>",
10161016
r" <Function test2>",
10171017
]
10181018
)

0 commit comments

Comments
 (0)