Fix a bug and add a test
This commit is contained in:
parent
80b4f8be1c
commit
0b725e70ab
|
@ -1486,7 +1486,12 @@ class FixtureManager:
|
|||
fixturedefs = self.getfixturedefs(argname, parentid)
|
||||
if fixturedefs:
|
||||
arg2fixturedefs[argname] = fixturedefs
|
||||
if argname in arg2fixturedefs:
|
||||
else:
|
||||
fixturedefs = arg2fixturedefs[argname]
|
||||
if fixturedefs and not (
|
||||
fixturedefs[-1].func.__name__ == "get_direct_param_fixture_func"
|
||||
and fixturedefs[-1].baseid == ""
|
||||
):
|
||||
fixturenames_closure = deduplicate_names(
|
||||
fixturenames_closure + arg2fixturedefs[argname][-1].argnames
|
||||
)
|
||||
|
|
|
@ -4619,6 +4619,32 @@ def test_reordering_after_dynamic_parametrize(pytester: Pytester):
|
|||
)
|
||||
|
||||
|
||||
def test_request_shouldnt_be_in_closure_after_pruning_dep_tree_when_its_not_in_initial_closure(
|
||||
pytester: Pytester,
|
||||
):
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
def pytest_generate_tests(metafunc):
|
||||
metafunc.parametrize("arg", [0])
|
||||
|
||||
@pytest.fixture()
|
||||
def fixture():
|
||||
pass
|
||||
|
||||
def test(fixture, arg):
|
||||
pass
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest("--setup-show")
|
||||
result.stdout.re_match_lines(
|
||||
[
|
||||
r".+test\[0\] \(fixtures used: arg, fixture\)\.",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def test_dont_recompute_dependency_tree_if_no_dynamic_parametrize(pytester: Pytester):
|
||||
pytester.makeconftest(
|
||||
"""
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import pytest
|
||||
from _pytest.pytester import Pytester
|
||||
|
||||
|
||||
|
@ -252,3 +253,39 @@ def test_verbose_include_multiline_docstring(pytester: Pytester) -> None:
|
|||
" Docstring content that extends into a third paragraph.",
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xfail(
|
||||
reason="python.py::show_fixtures_per_test uses arg2fixturedefs instead of fixtureclosure"
|
||||
)
|
||||
def test_should_not_show_fixtures_pruned_after_dynamic_parametrization(
|
||||
pytester: Pytester,
|
||||
) -> None:
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
def fixture1():
|
||||
pass
|
||||
|
||||
@pytest.fixture
|
||||
def fixture2(fixture1):
|
||||
pass
|
||||
|
||||
@pytest.fixture
|
||||
def fixture3(fixture2):
|
||||
pass
|
||||
|
||||
def pytest_generate_tests(metafunc):
|
||||
metafunc.parametrize("fixture3", [0])
|
||||
|
||||
def test(fixture3):
|
||||
pass
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest("--fixtures-per-test")
|
||||
result.stdout.re_match_lines(
|
||||
[r"-+ fixtures used by test\[0\] -+", r"-+ \(.+\) -+", r"fixture3 -- .+"],
|
||||
consecutive=True,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue