Skip to content

Commit 7918a44

Browse files
authored
Merge branch 'main' into fix/duplicate-pythonwarnings
2 parents a8d8cec + c8a4618 commit 7918a44

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ Mike Hoyle (hoylemd)
320320
Mike Lundy
321321
Milan Lesnek
322322
Miro Hrončok
323+
Mulat Mekonen
323324
mrbean-bremen
324325
Nathan Goldbaum
325326
Nathan Rousseau

changelog/13771.contrib.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Skip `test_do_not_collect_symlink_siblings` on Windows environments without symlink support to avoid false negatives.

testing/python/fixtures.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5071,6 +5071,42 @@ def test_method(self, /, fix):
50715071
result.assert_outcomes(passed=1)
50725072

50735073

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+
50745110
def test_fixture_closure_with_overrides(pytester: Pytester) -> None:
50755111
"""Test that an item's static fixture closure properly includes transitive
50765112
dependencies through overridden fixtures (#13773)."""

testing/test_collection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,8 @@ def test_do_not_collect_symlink_siblings(
18711871
"""
18721872
# Use tmp_path because it creates a symlink with the name "current" next to the directory it creates.
18731873
symlink_path = tmp_path.parent / (tmp_path.name[:-1] + "current")
1874-
assert symlink_path.is_symlink() is True
1874+
if not symlink_path.is_symlink(): # pragma: no cover
1875+
pytest.skip("Symlinks not supported in this environment")
18751876

18761877
# Create test file.
18771878
tmp_path.joinpath("test_foo.py").write_text("def test(): pass", encoding="UTF-8")

0 commit comments

Comments
 (0)