From 569dfaf513b96a9d3272144ec9ea99a1e1458e30 Mon Sep 17 00:00:00 2001 From: Andrzej Klajnert Date: Sun, 11 Sep 2022 10:33:53 +0200 Subject: [PATCH] Add test for collecting recursive symlinks --- testing/test_collection.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/testing/test_collection.py b/testing/test_collection.py index 58e1d862a..f308e9d75 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -274,6 +274,30 @@ class TestCollectFS: items, reprec = pytester.inline_genitems() assert [x.name for x in items] == ["test_%s" % dirname] + @pytest.mark.parametrize("absolute", [True, False]) + def test_recursive_symlinks(self, pytester, absolute): + """Make sure recursive symlinks won't cause multiple collection of the same file.""" + directory = pytester.mkdir("dir") + ensure_file(directory / "test_recursive.py").write_text( + "def test_recursive(): pass" + ) + symlink_or_skip(str(directory) if absolute else ".", "dir/link") + + items, _ = pytester.inline_genitems() + assert len(items) == 1 + + def test_multiple_recursive_symlinks(self, pytester): + """Symlink points to recursive symlink. Should be resolved to the very end.""" + directory = pytester.mkdir("dir") + ensure_file(directory / "test_recursive.py").write_text( + "def test_recursive(): pass" + ) + symlink_or_skip(".", "dir/link") + symlink_or_skip("link", "dir/link2") + + items, _ = pytester.inline_genitems() + assert len(items) == 1 + class TestCollectPluginHookRelay: def test_pytest_collect_file(self, pytester: Pytester) -> None: