Skip to content

Commit a14a229

Browse files
authored
Merge pull request #7982 from bluetech/symlink-collect
pathlib: fix symlinked directories not followed during collection
2 parents dd32398 + 6cdae8e commit a14a229

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

changelog/7981.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed symlinked directories not being followed during collection. Regressed in pytest 6.1.0.

src/_pytest/pathlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ def visit(
558558
entries = sorted(os.scandir(path), key=lambda entry: entry.name)
559559
yield from entries
560560
for entry in entries:
561-
if entry.is_dir(follow_symlinks=False) and recurse(entry):
561+
if entry.is_dir() and recurse(entry):
562562
yield from visit(entry.path, recurse)
563563

564564

testing/test_collection.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from _pytest.main import _in_venv
1010
from _pytest.main import Session
1111
from _pytest.pathlib import symlink_or_skip
12+
from _pytest.pytester import Pytester
1213
from _pytest.pytester import Testdir
1314

1415

@@ -1178,6 +1179,15 @@ def test_nodeid(request):
11781179
assert result.ret == 0
11791180

11801181

1182+
def test_collect_symlink_dir(pytester: Pytester) -> None:
1183+
"""A symlinked directory is collected."""
1184+
dir = pytester.mkdir("dir")
1185+
dir.joinpath("test_it.py").write_text("def test_it(): pass", "utf-8")
1186+
pytester.path.joinpath("symlink_dir").symlink_to(dir)
1187+
result = pytester.runpytest()
1188+
result.assert_outcomes(passed=2)
1189+
1190+
11811191
def test_collectignore_via_conftest(testdir):
11821192
"""collect_ignore in parent conftest skips importing child (issue #4592)."""
11831193
tests = testdir.mkpydir("tests")

0 commit comments

Comments
 (0)