From 569dfaf513b96a9d3272144ec9ea99a1e1458e30 Mon Sep 17 00:00:00 2001 From: Andrzej Klajnert Date: Sun, 11 Sep 2022 10:33:53 +0200 Subject: [PATCH 1/2] 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 58e1d862a35..f308e9d7523 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -274,6 +274,30 @@ def test_testpaths_ini(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> No 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: From be245dc7c3834890fe4f6642c7206c5ffa5e9397 Mon Sep 17 00:00:00 2001 From: Andrzej Klajnert Date: Sun, 11 Sep 2022 10:58:47 +0200 Subject: [PATCH 2/2] Add xfail to the recursive symlink tests --- testing/test_collection.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testing/test_collection.py b/testing/test_collection.py index f308e9d7523..01f2c471ac6 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -274,6 +274,7 @@ def test_testpaths_ini(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> No items, reprec = pytester.inline_genitems() assert [x.name for x in items] == ["test_%s" % dirname] + @pytest.mark.xfail(sys.platform == "linux", reason="GitHub #624") @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.""" @@ -286,6 +287,7 @@ def test_recursive_symlinks(self, pytester, absolute): items, _ = pytester.inline_genitems() assert len(items) == 1 + @pytest.mark.xfail(sys.platform == "linux", reason="GitHub #624") def test_multiple_recursive_symlinks(self, pytester): """Symlink points to recursive symlink. Should be resolved to the very end.""" directory = pytester.mkdir("dir")