Skip to content

Commit 4e43db6

Browse files
committed
Add test for collecting recursive symlinks
1 parent ced125a commit 4e43db6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

testing/test_collection.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,30 @@ def test_testpaths_ini(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> No
265265
items, reprec = pytester.inline_genitems()
266266
assert [x.name for x in items] == ["test_%s" % dirname]
267267

268+
@pytest.mark.parametrize("absolute", [True, False])
269+
def test_recursive_symlinks(self, pytester, absolute):
270+
"""Make sure recursive symlinks won't cause multiple collection of the same file."""
271+
directory = pytester.mkdir("dir")
272+
ensure_file(directory / "test_recursive.py").write_text(
273+
"def test_recursive(): pass"
274+
)
275+
symlink_or_skip(str(directory) if absolute else ".", "dir/link")
276+
277+
items, _ = pytester.inline_genitems()
278+
assert len(items) == 1
279+
280+
def test_multiple_recursive_symlinks(self, pytester):
281+
"""Symlink points to recursive symlink. Should be resolved to the very end."""
282+
directory = pytester.mkdir("dir")
283+
ensure_file(directory / "test_recursive.py").write_text(
284+
"def test_recursive(): pass"
285+
)
286+
symlink_or_skip(".", "dir/link")
287+
symlink_or_skip("link", "dir/link2")
288+
289+
items, _ = pytester.inline_genitems()
290+
assert len(items) == 1
291+
268292

269293
class TestCollectPluginHookRelay:
270294
def test_pytest_collect_file(self, pytester: Pytester) -> None:

0 commit comments

Comments
 (0)