Skip to content

fix(tests): wrap Path.expanduser() to never raise on Windows runner#1276

Merged
danielmeppiel merged 2 commits into
mainfrom
fix/windows-expanduser
May 11, 2026
Merged

fix(tests): wrap Path.expanduser() to never raise on Windows runner#1276
danielmeppiel merged 2 commits into
mainfrom
fix/windows-expanduser

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

Problem

The v0.13.0 retag CI still red-marked Windows on two tests after #1272:

FAILED tests/unit/install/test_user_scope_rejection_reason.py::test_user_scope_accepts_tilde_local_path[~/pkg]
FAILED tests/unit/install/test_user_scope_rejection_reason.py::test_user_scope_accepts_tilde_local_path[~/sub/pkg]
       raise RuntimeError("Could not determine home directory.")
E      RuntimeError: Could not determine home directory.
C:\hostedtoolcache\windows\Python\3.12.10\x64\Lib\pathlib.py:1406: RuntimeError

Different code path than #1272: production code in install.package_resolution.user_scope_rejection_reason calls Path('~/pkg').expanduser() to detect absoluteness. ntpath.expanduser raises RuntimeError when both USERPROFILE and HOMEPATH are absent — the windows-2025-vs2026 runner state.

Fix

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). Expanded path is still absolute so production code's .is_absolute() check still behaves correctly.

Validation

  • New regression-trap test in tests/unit/test_path_home_override.py (clears HOME/USERPROFILE/HOMEDRIVE/HOMEPATH, asserts Path('~/pkg').expanduser() returns an absolute path without raising).
  • The two previously-failing tests now pass locally.
  • Lint clean.

Why ship now

Required for v0.13.0 retag to go green on Windows.

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>
Copilot AI review requested due to automatic review settings May 11, 2026 13:25
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@danielmeppiel danielmeppiel merged commit 9216516 into main May 11, 2026
9 checks passed
@danielmeppiel danielmeppiel deleted the fix/windows-expanduser branch May 11, 2026 13:47
@danielmeppiel danielmeppiel review requested due to automatic review settings May 11, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant