Skip to content

Skip symlink tests when the platform forbids creating one - #5390

Merged
cobaltt7 merged 1 commit into
psf:mainfrom
istoolsfox:skip-symlink-tests-when-forbidden
Sep 16, 2026
Merged

cobaltt7 merged 1 commit into
psf:mainfrom
istoolsfox:skip-symlink-tests-when-forbidden

Conversation

@istoolsfox

@istoolsfox istoolsfox commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5389.

What

Three tests in TestFileCollection create symlinks without any guard, so the test suite fails with OSError: [WinError 1314] for any Windows contributor who is neither elevated nor running with Developer Mode enabled:

  • test_get_sources_symlink_and_force_exclude
  • test_get_sources_with_stdin_symlink_outside_root
  • test_get_sources_with_stdin_filename_and_force_exclude_and_symlink

This is the same problem #287 fixed in 2018 for test_broken_symlink — that guard is still in place and working, but the three tests above were added later without it. CI cannot catch the regression because the Windows runner can create symlinks; only an ordinary local Windows checkout fails.

Change

Add a module-level symlink_or_skip(link, target) helper next to the other test utilities and use it at all five symlink_to call sites in TestFileCollection:

def symlink_or_skip(link: Path, target: Path | str) -> None:
    try:
        link.symlink_to(target)
    except (OSError, NotImplementedError) as e:
        pytest.skip(f"Can't create symlinks: {e}")

Notes:

  • pytest.skip instead of self.skipTest, since TestFileCollection is a plain pytest class, not a unittest.TestCase (test_broken_symlink keeps its existing skipTest guard).
  • Centralising the helper means the next symlink test picks up the guard by default, which is what would have prevented this recurrence.
  • The fix follows the approach suggested in the issue (thanks @iam-kira for the detailed report and verification).

Verification

  • Before: 3 failed, 442 passed on Windows (WinError 1314) — matches the issue report.
  • After: 0 failed / 442 passed, with the three tests reporting SKIPPED (Can't create symlinks: ...).
  • Full suite: 442 passed, 7 skipped, 8 subtests passed (pytest --ignore=tests/test_blackd.py).
  • black --check tests/test_black.py, flake8, isort --check-only, and mypy all pass.

Changelog

Test-only change with no user-facing behaviour impact, so I believe no CHANGES.md entry is needed — happy to add one under the appropriate heading if you prefer.

Three tests in TestFileCollection create symlinks without a guard, so
they fail with WinError 1314 for any Windows contributor who is not
elevated and does not have Developer Mode enabled. The guard pattern
already exists since GH psf#287 (test_broken_symlink), but the three
tests added later never picked it up. CI cannot catch this because
the Windows runner can create symlinks.

Add a shared symlink_or_skip helper (pytest.skip, as TestFileCollection
is a plain pytest class) and use it at all five symlink_to call sites,
so the next symlink test picks up the guard by default.

On Windows: 3 failed / 442 passed -> 0 failed / 442 passed, with the
three tests reporting a clear skip reason.
@istoolsfox

Copy link
Copy Markdown
Contributor Author

Test-only change — no user-facing behavior is touched, so there's nothing to report in CHANGES.md. Could a maintainer add the ci: skip news label? Thanks!

@cobaltt7 cobaltt7 added the ci: skip news Pull requests that don't need a changelog entry. label Sep 16, 2026
@cobaltt7

Copy link
Copy Markdown
Collaborator

Thanks!

@cobaltt7
cobaltt7 merged commit acd6198 into psf:main Sep 16, 2026
48 of 49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci: skip news Pull requests that don't need a changelog entry.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Three symlink tests fail on Windows without symlink privilege (regression of #287)

2 participants