Repository navigation
Conversation
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
RonnyPfannschmidt
approved these changes
Nov 19, 2026
RonnyPfannschmidt
approved these changes
Nov 19, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On Windows, pytest fails at the end of the session when the process runs with RedirectionGuard enabled. All tests pass, but the summary line is not printed and the session exits with code 1:
(My Windows is in Spanish, so I translated the message. The error code is the original.)
I found this running the test suite of a personal project from a sandboxed agent session on Windows 11. Processes in that sandbox run with RedirectionGuard, so Windows refuses to follow any symlink or junction and returns
ERROR_UNTRUSTED_MOUNT_POINT(448). In my project I worked around it by wrappingcleanup_dead_symlinksin aconftest.py.cleanup_dead_symlinkscallsPath.resolve()on every symlink in the basetemp. In non-strict modentpath.realpathonly ignores a fixed list of Windows errors, and 448 is not in it (CPython main,Lib/ntpath.py, same on 3.12 to 3.14). So the error reaches pytest. The function runs inpytest_sessionfinishand in the exit stack of the numbered dir cleanup, so the session fails after all the tests have passed.This PR:
resolve()raisesOSError, and continues with the next entry;This follows the idea of
_force_symlink, which already ignores errors because thecurrentlinks are best effort.#15174 changes the next line (
unlink(missing_ok=True)). The two changes are independent. I am happy to rebase on whichever is merged first.How to reproduce
run_guarded.pyenables RedirectionGuard in the current process and then runs pytest:Python has to start from a real path. If it starts through a junction (for example the
cpython-3.12-windows-x86_64-nonealias that uv creates), imports fail before pytest gets to the cleanup.Results
Windows 11, CPython 3.12.13, pytest
mainat 9efd012:mainrun_guarded.py(one session)WinError 4481 passedrun_guarded.py(6 sessions in a row)test_cleanup_keeps_symlink_that_cannot_be_resolvedtesting/test_tmpdir.pypre-commitpasses on the changed files.I used Claude Code to investigate the problem and write the change. I have reviewed every line and I understand it. The commit credits it with a
Co-authored-bytrailer.Co-authored-bycommit trailers.changelogdirectory, with a name like<ISSUE NUMBER>.<TYPE>.rst.AUTHORSin alphabetical order.