fix(tests): wrap Path.expanduser() to never raise on Windows runner#1276
Merged
Conversation
Companion to #1272. After the Path.home() override landed, the windows-2025-vs2026 runner still red-marked two tests: tests/unit/install/test_user_scope_rejection_reason.py ::test_user_scope_accepts_tilde_local_path[~/pkg] ::test_user_scope_accepts_tilde_local_path[~/sub/pkg] These hit a different code path: production code in install.package_resolution.user_scope_rejection_reason calls Path('~/pkg').expanduser() to detect that the path is absolute. ntpath.expanduser raises RuntimeError('Could not determine home directory.') when both USERPROFILE and HOMEPATH are absent -- exactly the windows-2025-vs2026 worker env state. Fix in tests/conftest.py (root, loaded by every xdist worker before any test): - Wrap Path.expanduser. On RuntimeError, fall back to _TMP_HOME (the same hermetic dir Path.home() uses). The expanded path is still absolute, so production code's .is_absolute() check keeps behaving correctly. Regression trap added in tests/unit/test_path_home_override.py: clears HOME/USERPROFILE/HOMEDRIVE/HOMEPATH and asserts Path('~/pkg').expanduser() returns an absolute path without raising. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Problem
The v0.13.0 retag CI still red-marked Windows on two tests after #1272:
Different code path than #1272: production code in
install.package_resolution.user_scope_rejection_reasoncallsPath('~/pkg').expanduser()to detect absoluteness.ntpath.expanduserraisesRuntimeErrorwhen bothUSERPROFILEandHOMEPATHare absent — the windows-2025-vs2026 runner state.Fix
tests/conftest.py(root, loaded by every xdist worker before any test): wrapPath.expanduser. OnRuntimeError, fall back to_TMP_HOME(the same hermetic dirPath.home()uses). Expanded path is still absolute so production code's.is_absolute()check still behaves correctly.Validation
tests/unit/test_path_home_override.py(clears HOME/USERPROFILE/HOMEDRIVE/HOMEPATH, assertsPath('~/pkg').expanduser()returns an absolute path without raising).Why ship now
Required for v0.13.0 retag to go green on Windows.