Skip to content

Revert the unintended change in tests reordering from #11220 #12542

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

Merged
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
1 change: 1 addition & 0 deletions changelog/12008.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +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.
10 changes: 10 additions & 0 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ def _genfunctions(self, name: str, funcobj) -> Iterator[Function]:
if not metafunc._calls:
yield Function.from_parent(self, name=name, fixtureinfo=fixtureinfo)
else:
metafunc._recompute_direct_params_indices()
# Direct parametrizations taking place in module/class-specific
# `metafunc.parametrize` calls may have shadowed some fixtures, so make sure
# we update what the function really needs a.k.a its fixture closure. Note that
Expand Down Expand Up @@ -1131,6 +1132,8 @@ def __init__(
# Result of parametrize().
self._calls: list[CallSpec2] = []

self._params_directness: dict[str, Literal["indirect", "direct"]] = {}

def parametrize(
self,
argnames: str | Sequence[str],
Expand Down Expand Up @@ -1273,6 +1276,7 @@ def parametrize(
name2pseudofixturedef_key, default
)
arg_directness = self._resolve_args_directness(argnames, indirect)
self._params_directness.update(arg_directness)
for argname in argnames:
if arg_directness[argname] == "indirect":
continue
Expand Down Expand Up @@ -1445,6 +1449,12 @@ def _validate_if_using_arg_names(
pytrace=False,
)

def _recompute_direct_params_indices(self) -> None:
for argname, param_type in self._params_directness.items():
if param_type == "direct":
for i, callspec in enumerate(self._calls):
callspec.indices[argname] = i


def _find_parametrized_scope(
argnames: Sequence[str],
Expand Down
4 changes: 2 additions & 2 deletions testing/example_scripts/issue_519.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ def checked_order():
assert order == [
("issue_519.py", "fix1", "arg1v1"),
("test_one[arg1v1-arg2v1]", "fix2", "arg2v1"),
("test_one[arg1v1-arg2v2]", "fix2", "arg2v2"),
("test_two[arg1v1-arg2v1]", "fix2", "arg2v1"),
("test_one[arg1v1-arg2v2]", "fix2", "arg2v2"),
("test_two[arg1v1-arg2v2]", "fix2", "arg2v2"),
("issue_519.py", "fix1", "arg1v2"),
("test_one[arg1v2-arg2v1]", "fix2", "arg2v1"),
("test_one[arg1v2-arg2v2]", "fix2", "arg2v2"),
("test_two[arg1v2-arg2v1]", "fix2", "arg2v1"),
("test_one[arg1v2-arg2v2]", "fix2", "arg2v2"),
("test_two[arg1v2-arg2v2]", "fix2", "arg2v2"),
]

Expand Down
6 changes: 3 additions & 3 deletions testing/python/metafunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,14 +1005,14 @@ def test3(arg1):
result.stdout.re_match_lines(
[
r" <Function test1\[0-3\]>",
r" <Function test1\[0-4\]>",
r" <Function test3\[0\]>",
r" <Function test1\[0-4\]>",
r" <Function test3\[1\]>",
r" <Function test1\[1-3\]>",
r" <Function test3\[2\]>",
r" <Function test1\[1-4\]>",
r" <Function test3\[1\]>",
r" <Function test1\[2-3\]>",
r" <Function test1\[2-4\]>",
r" <Function test3\[2\]>",
r" <Function test2>",
]
)
Expand Down
Loading