Do the change
This commit is contained in:
parent
0ed2d79457
commit
e7e7719d4a
|
@ -464,6 +464,7 @@ class PyCollector(PyobjMixin, nodes.Collector, abc.ABC):
|
||||||
if not metafunc._calls:
|
if not metafunc._calls:
|
||||||
yield Function.from_parent(self, name=name, fixtureinfo=fixtureinfo)
|
yield Function.from_parent(self, name=name, fixtureinfo=fixtureinfo)
|
||||||
else:
|
else:
|
||||||
|
metafunc._recompute_direct_params_indices()
|
||||||
# Direct parametrizations taking place in module/class-specific
|
# Direct parametrizations taking place in module/class-specific
|
||||||
# `metafunc.parametrize` calls may have shadowed some fixtures, so make sure
|
# `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
|
# we update what the function really needs a.k.a its fixture closure. Note that
|
||||||
|
@ -1131,6 +1132,8 @@ class Metafunc:
|
||||||
# Result of parametrize().
|
# Result of parametrize().
|
||||||
self._calls: list[CallSpec2] = []
|
self._calls: list[CallSpec2] = []
|
||||||
|
|
||||||
|
self._params_directness: dict[str, Literal["indirect", "direct"]] = {}
|
||||||
|
|
||||||
def parametrize(
|
def parametrize(
|
||||||
self,
|
self,
|
||||||
argnames: str | Sequence[str],
|
argnames: str | Sequence[str],
|
||||||
|
@ -1273,6 +1276,7 @@ class Metafunc:
|
||||||
name2pseudofixturedef_key, default
|
name2pseudofixturedef_key, default
|
||||||
)
|
)
|
||||||
arg_directness = self._resolve_args_directness(argnames, indirect)
|
arg_directness = self._resolve_args_directness(argnames, indirect)
|
||||||
|
self._params_directness.update(arg_directness)
|
||||||
for argname in argnames:
|
for argname in argnames:
|
||||||
if arg_directness[argname] == "indirect":
|
if arg_directness[argname] == "indirect":
|
||||||
continue
|
continue
|
||||||
|
@ -1445,6 +1449,12 @@ class Metafunc:
|
||||||
pytrace=False,
|
pytrace=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _recompute_direct_params_indices(self):
|
||||||
|
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(
|
def _find_parametrized_scope(
|
||||||
argnames: Sequence[str],
|
argnames: Sequence[str],
|
||||||
|
|
|
@ -23,13 +23,13 @@ def checked_order():
|
||||||
assert order == [
|
assert order == [
|
||||||
("issue_519.py", "fix1", "arg1v1"),
|
("issue_519.py", "fix1", "arg1v1"),
|
||||||
("test_one[arg1v1-arg2v1]", "fix2", "arg2v1"),
|
("test_one[arg1v1-arg2v1]", "fix2", "arg2v1"),
|
||||||
("test_one[arg1v1-arg2v2]", "fix2", "arg2v2"),
|
|
||||||
("test_two[arg1v1-arg2v1]", "fix2", "arg2v1"),
|
("test_two[arg1v1-arg2v1]", "fix2", "arg2v1"),
|
||||||
|
("test_one[arg1v1-arg2v2]", "fix2", "arg2v2"),
|
||||||
("test_two[arg1v1-arg2v2]", "fix2", "arg2v2"),
|
("test_two[arg1v1-arg2v2]", "fix2", "arg2v2"),
|
||||||
("issue_519.py", "fix1", "arg1v2"),
|
("issue_519.py", "fix1", "arg1v2"),
|
||||||
("test_one[arg1v2-arg2v1]", "fix2", "arg2v1"),
|
("test_one[arg1v2-arg2v1]", "fix2", "arg2v1"),
|
||||||
("test_one[arg1v2-arg2v2]", "fix2", "arg2v2"),
|
|
||||||
("test_two[arg1v2-arg2v1]", "fix2", "arg2v1"),
|
("test_two[arg1v2-arg2v1]", "fix2", "arg2v1"),
|
||||||
|
("test_one[arg1v2-arg2v2]", "fix2", "arg2v2"),
|
||||||
("test_two[arg1v2-arg2v2]", "fix2", "arg2v2"),
|
("test_two[arg1v2-arg2v2]", "fix2", "arg2v2"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -4878,3 +4878,37 @@ def test_subfixture_teardown_order(pytester: Pytester) -> None:
|
||||||
)
|
)
|
||||||
result = pytester.runpytest()
|
result = pytester.runpytest()
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_reordering_in_multiple_parametrization(pytester: Pytester) -> None:
|
||||||
|
pytester.makepyfile(
|
||||||
|
"""
|
||||||
|
import pytest
|
||||||
|
@pytest.mark.parametrize("arg2", [3, 4])
|
||||||
|
@pytest.mark.parametrize("arg1", [0, 1, 2], scope='module')
|
||||||
|
def test1(arg1, arg2):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test2():
|
||||||
|
pass
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("arg1", [0, 1, 2], scope='module')
|
||||||
|
def test3(arg1):
|
||||||
|
pass
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
result = pytester.runpytest("--collect-only")
|
||||||
|
result.stdout.re_match_lines(
|
||||||
|
[
|
||||||
|
r" <Function test1\[0-3\]>",
|
||||||
|
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 test1\[2-3\]>",
|
||||||
|
r" <Function test1\[2-4\]>",
|
||||||
|
r" <Function test2>",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue