Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/7981.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed symlinked directories not being followed during collection. Regressed in pytest 6.1.0.
2 changes: 1 addition & 1 deletion src/_pytest/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def visit(
entries = sorted(os.scandir(path), key=lambda entry: entry.name)
yield from entries
for entry in entries:
if entry.is_dir(follow_symlinks=False) and recurse(entry):
if entry.is_dir() and recurse(entry):
yield from visit(entry.path, recurse)


Expand Down
10 changes: 10 additions & 0 deletions testing/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from _pytest.main import _in_venv
from _pytest.main import Session
from _pytest.pathlib import symlink_or_skip
from _pytest.pytester import Pytester
from _pytest.pytester import Testdir


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


def test_collect_symlink_dir(pytester: Pytester) -> None:
"""A symlinked directory is collected."""
dir = pytester.mkdir("dir")
dir.joinpath("test_it.py").write_text("def test_it(): pass", "utf-8")
pytester.path.joinpath("symlink_dir").symlink_to(dir)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, should have used symlink_or_skip here, and absent that, should have used symlink_to(dir, target_is_directory=True). I wonder how it passed windows CI without it. Will fix it anyway.

result = pytester.runpytest()
result.assert_outcomes(passed=2)


def test_collectignore_via_conftest(testdir):
"""collect_ignore in parent conftest skips importing child (issue #4592)."""
tests = testdir.mkpydir("tests")
Expand Down