forked from pytest-dev/pytest
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
User Request
Symlinked directories not collected since pytest 6.1.0
When there is a symlink to a directory in a test directory, it is just skipped over, but it should be followed and collected as usual.
This regressed in b473e51 (included in 6.1.0). For some reason a follow_symlinks=False was added in there; it does not match the previous behavior and should be removed.
PR for this is coming up.
Active code branch for implementation: pytest-dev__pytest-7982
Research Specification
- Regression source:
src/_pytest/pathlib.pyvisit()introducedfollow_symlinks=False, preventing descent into symlinked directories. - Expected behavior: follow symlinked directories during collection (pre-6.1.0 behavior), for both
DirandPackagecollectors.
Change Details
- File:
src/_pytest/pathlib.py- Function:
visit(path, recurse) - Current (branch
pytest-dev__pytest-7982):entries = sorted(os.scandir(path), key=lambda entry: entry.name)if entry.is_dir(follow_symlinks=False) and recurse(entry):
- Change:
- Replace
follow_symlinks=Falsewithfollow_symlinks=True.
- Replace
- Rationale: disabling symlink follow caused silent skipping of symlinked directories; restoring default behavior aligns with older versions and current
Dir/Packagecollectors.
- Function:
Compatibility & Risks
- Windows symlink support: use
symlink_or_skipin tests to skip when unsupported. - Broken symlinks: remain uncollected; behavior unchanged.
- Symlink loops: following symlinks can introduce cycles; if necessary, in future consider a visited set of
(st_dev, st_ino)to avoid recursion loops.
Test Plan
Add tests ensuring symlinked directories are collected:
test_collect_symlinked_dir_as_dircollector: createreal_sub/test_in_real.py, symlinklink_sub -> real_sub; runpytest -q, assert tests under bothreal_subandlink_subare collected.test_collect_symlinked_dir_as_packagecollector: package structure with__init__.pyand symlinkedlink_subtoreal_sub; assert tests collected under both.
Reproduction and Observed Failure (current branch)
- DirCollector case: only
real_subtests are collected;link_subcontents are skipped. No stack trace; silent skip.-vvshows traversal ofreal_subbut notlink_sub. - PackageCollector case: same behavior; only
real_subcollected.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels