@@ -5071,6 +5071,42 @@ def test_method(self, /, fix):
5071
5071
result .assert_outcomes (passed = 1 )
5072
5072
5073
5073
5074
+ def test_parametrization_dependency_pruning (pytester : Pytester ) -> None :
5075
+ """Test that when a fixture is dynamically shadowed by parameterization, it
5076
+ is properly pruned and not executed."""
5077
+ pytester .makepyfile (
5078
+ """
5079
+ import pytest
5080
+
5081
+
5082
+ # This fixture should never run because shadowed_fixture is parametrized.
5083
+ @pytest.fixture
5084
+ def boom():
5085
+ raise RuntimeError("BOOM!")
5086
+
5087
+
5088
+ # This fixture is shadowed by metafunc.parametrize in pytest_generate_tests.
5089
+ @pytest.fixture
5090
+ def shadowed_fixture(boom):
5091
+ return "fixture_value"
5092
+
5093
+
5094
+ # Dynamically parametrize shadowed_fixture, replacing the fixture with direct values.
5095
+ def pytest_generate_tests(metafunc):
5096
+ if "shadowed_fixture" in metafunc.fixturenames:
5097
+ metafunc.parametrize("shadowed_fixture", ["param1", "param2"])
5098
+
5099
+
5100
+ # This test should receive shadowed_fixture as a parametrized value, and
5101
+ # boom should not explode.
5102
+ def test_shadowed(shadowed_fixture):
5103
+ assert shadowed_fixture in ["param1", "param2"]
5104
+ """
5105
+ )
5106
+ result = pytester .runpytest ()
5107
+ result .assert_outcomes (passed = 2 )
5108
+
5109
+
5074
5110
def test_fixture_closure_with_overrides (pytester : Pytester ) -> None :
5075
5111
"""Test that an item's static fixture closure properly includes transitive
5076
5112
dependencies through overridden fixtures (#13773)."""
0 commit comments