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 <bruno@soliv.dev>
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
This commit is contained in:
Sadra Barikbin 2024-08-11 08:06:32 +03:30 committed by GitHub
parent cb98538e9c
commit 6a3ac51ee2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 6 deletions

View File

@ -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.

View File

@ -464,6 +464,7 @@ class PyCollector(PyobjMixin, nodes.Collector, abc.ABC):
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
@ -1131,6 +1132,8 @@ class Metafunc:
# Result of parametrize().
self._calls: list[CallSpec2] = []
self._params_directness: dict[str, Literal["indirect", "direct"]] = {}
def parametrize(
self,
argnames: str | Sequence[str],
@ -1273,6 +1276,7 @@ class Metafunc:
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
@ -1445,6 +1449,12 @@ class Metafunc:
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],

View File

@ -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"),
]

View File

@ -1005,14 +1005,14 @@ class TestMetafunc:
result.stdout.re_match_lines(
[
r" <Function test1\[0-3\]>",
r" <Function test1\[0-4\]>",
r" <Function test3\[0\]>",
r" <Function test1\[1-3\]>",
r" <Function test1\[1-4\]>",
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 test1\[2-3\]>",
r" <Function test1\[2-4\]>",
r" <Function test3\[2\]>",
r" <Function test2>",
]
)