fix(tests): hermetic HOME for unit tests on Windows runner#1270
Merged
Conversation
…d mock gap The new windows-2025-vs2026 GitHub-hosted runner image does not seed USERPROFILE/HOMEDRIVE+HOMEPATH for pytest workers, causing 56 unit-test failures with 'RuntimeError: Could not determine home directory' from Path.home(). A session-scoped autouse conftest fixture pins HOME (POSIX) and USERPROFILE/HOMEDRIVE/HOMEPATH (Windows) to a tmp dir for the entire unit-test session, restoring previous values on teardown. Per-test monkeypatch fixtures still win for their tests. Separately, test_update_command_respects_disabled_policy patched only apm_cli.commands.self_update.is_self_update_enabled but missed the matching import in apm_cli.commands._helpers (used by _check_and_notify_updates on every CLI invocation), letting requests.get fire whenever the version-check cache was cold. Linux xdist workers inherited a primed cache from neighbouring tests; Windows workers did not, surfacing the latent gap. Add the second @patch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2b63614 to
409ba3b
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Windows CI unit test failures by making Path.home() deterministic in unit tests and by correctly patching an import-bound is_self_update_enabled() symbol so the disabled-self-update test cannot accidentally hit the network.
Changes:
- Add a session-scoped autouse unit-test fixture that sets a hermetic HOME/USERPROFILE (and related Windows vars) for the duration of
tests/unit. - Fix
test_update_command_respects_disabled_policyby also patchingapm_cli.commands._helpers.is_self_update_enabled. - Add a changelog entry under
Unreleased.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/conftest.py | Adds session-wide hermetic HOME environment setup so Path.home() works reliably (including on Windows runners). |
| tests/unit/test_update_command.py | Ensures the disabled-self-update test patches the correct import binding to prevent unintended network calls. |
| CHANGELOG.md | Documents the test-infra fix under Unreleased. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 1
|
|
||
| ### Fixed | ||
|
|
||
| - Pin `Path.home()` under unit tests via a session-scoped autouse conftest fixture, fixing 56 Windows runner failures on the new `windows-2025-vs2026` GitHub-hosted image where `USERPROFILE`/`HOMEDRIVE`+`HOMEPATH` are not seeded for pytest workers; also patch the `_check_and_notify_updates` import binding in the disabled-self-update test so it no longer races on the version-check cache. (#1270) |
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.
TL;DR
The post-tag CI/CD Pipeline run on
v0.13.0(25660187642) failed Windows unit tests with 57 failures:RuntimeError: Could not determine home directoryfromPath.home()intests/unit/test_runtime_manager.pyandtests/unit/test_runtime_detection.py.test_update_command_respects_disabled_policy--requests.getcalled once when it should not have been.Both were latent test-infra issues exposed by GitHub redirecting
windows-latestfromwindows-2025towindows-2025-vs2026. No product code change.Problem
1. Path.home() on the new Windows image
Path.home()on Windows readsUSERPROFILEfirst, thenHOMEDRIVE+HOMEPATH. Thewindows-2025-vs2026image does not seed any of these for pytest worker subprocesses. Any unit test that touchesPath.home()(directly or viaget_user_runtime_dir()etc.) raises.2. Missed mock in disabled-self-update test
apm_cli/commands/_helpers.pydoesfrom ..update_policy import ... is_self_update_enabled, rebinding the symbol locally._check_and_notify_updates()runs on everycli()invocation. The test only patchedapm_cli.commands.self_update.is_self_update_enabled, leaving the_helpersreference live. On Linux xdist workers an earlier test primed~/.cache/apm/last_version_checksoshould_check_for_updates()skipped the network call; Windows workers were cold, sorequests.getfired.Fix
tests/unit/conftest.py(new) -- session-scoped autouse_hermetic_homefixture pinsPath.home()to a tmp dir viatmp_path_factory.mktemp. SetsHOMEon POSIX andUSERPROFILE/HOMEDRIVE/HOMEPATHon Windows. Restores prior values on teardown. Per-testmonkeypatch.setenvfixtures (_set_homeetc.) keep working for their scope.tests/unit/test_update_command.py-- stack a second@patch("apm_cli.commands._helpers.is_self_update_enabled", return_value=False)ontest_update_command_respects_disabled_policyand add the matching mock arg.Validation
Ran locally on macOS:
Lint mirror clean:
Cannot reproduce the
USERPROFILEdrift on macOS, but the conftest fix unifies behaviour with the existing per-test_set_homehelper attests/unit/integration/test_scope_integration.py:25-40, so the Windows runner will now see a stablePath.home()for every unit test.How to test
Triggered on push to
fix/windows-home-runner; the merge will re-trigger theCI/CD Pipelinejob on Windows after we re-tagv0.13.0.