Repository navigation
fix(tests): let the installer suites run on a Windows host - #4130
Conversation
The Windows unit lane errored out 19 times before reaching a single
assertion: every `patch("os.geteuid", ...)` raised AttributeError because
the attribute is POSIX-only and mock refuses to patch what does not exist.
Nineteen, not the seven originally reported — one autouse fixture in the
macOS suite took all twelve of its tests down with it.
`create=True` at each patch site lets mock invent the attribute for the
duration, which is exactly the euid the code under test would have seen.
The production code needed no change: every call site in
lemonade_installer.py already guards with hasattr.
Also fixes the one remaining Windows failure in the same file, which was a
different bug — the macOS detection test compared `str(Path("/usr/..."))`,
which a Windows host renders with backslashes so it matched nothing.
Comparing as POSIX keeps the assertion equally strict everywhere.
Finally, .pylintrc now lists os.killpg/getpgid/geteuid as generated members.
astroid resolves os against the running interpreter, so `util/lint.py`
reported nine E1101s on Windows for guarded, correct code. CI lints on Linux
and never saw them.
|
Reproduced and verified this end to end on a real Windows box — both the problem and the fix. Worth recording, because every lane in this PR's own CI runs on Linux, so none of them can confirm the thing it claims to fix. Before: the two installer suites produce 20 failures before a single assertion runs (19 🔍 Technical detailsWindows 11, Python 3.13, this PR's three files checked out over current
Two things I checked that could have been gaps, and are not:
Only red is |
The module docstring said the file was kept separate because the install suite patches os.geteuid and therefore errors on Windows. That is no longer true, and leaving it would send the next reader looking for a bug that has been fixed. The split still has a real reason: these are string assertions against the pinned .pkg BOMs, not install control flow.
|
Independently reproduced on a Windows box, with a number this PR can't see from inside: these two suites go from 8 failed + 12 errors to 0 once it lands, and that's 20 of the 131 failures that survive #4115 — the single largest remaining cause in the local Windows unit suite. I'd arrived at 🔍 Technical detailsMeasured against a full
19 of the 20 are literally the same Checked with the patch applied locally: The |
Running the unit tests on a Windows box errored out 19 times before reaching a
single assertion, so the installer suites were effectively unrunnable on that
platform.
os.geteuidis POSIX-only, andunittest.mock.patchrefuses to patchan attribute that does not exist. Both installer suites now pass on Windows and
are unchanged on Linux and macOS. Closes #4127.
Three things, all in the same lane:
geteuidpatches — 19 tests, not the 7 in the issue. Oneautousefixture in the macOS suite took all twelve of its own tests down with it.
compared paths as native strings, which a Windows host renders with
backslashes, so nothing ever matched. Comparing as POSIX keeps the assertion
equally strict everywhere.
util/lint.pyflaggedos.killpg/os.getpgid/os.geteuidindaemon/sidecars/andinstaller/as missing members. The code is correct and guarded at runtime;CI lints on Linux and never saw them.
No production code changed — every call site was already guarded.
🔍 Technical details
patch(target)defaults tocreate=False, soget_original()raisesAttributeErrorwhen the attribute is absent.create=Trueinvents it for thepatch's duration and
delattrs it on exit, so nothing leaks between tests — andthe injected euid is exactly what the code under test would have read on POSIX.
Sites: seven decorators in
TestInstallViaPpa(
tests/unit/test_init_command.py), plus the_non_rootautouse fixture and theroot-case patch in
tests/unit/test_lemonade_macos_install.py.src/gaia/installer/lemonade_installer.pyneeded nothing — all three call sites(723, 909, 1196) already sit behind
hasattr(os, "geteuid").The path bug:
test_check_installation_finds_macos_installstubsPath.existswith a set membership test, but
str(Path("/usr/local/bin/lemond"))is\usr\local\bin\lemondon Windows. Both the stub and theinfo.pathassertionnow normalise through
as_posix().pylint: astroid resolves
osmembers against the running interpreter, so theseare false positives that can only fire on Windows. Adding the three names to
generated-membersin.pylintrcis a no-op on Linux — the check never firedthere — and the rcfile's own header endorses suppressing rare false positives
rather than dropping a valuable check wholesale. Note line 1197 never tripped:
pylint understands the
if hasattr(...)statement form but not thehasattr(...) and ...boolean form used at 723 and 909.Test plan
python -m pytest tests/unit/test_init_command.py tests/unit/test_lemonade_macos_install.py -qon Windows 11 — 144 passed, 9 subtests passed, was 1 failed / 19 errorspython util/lint.py --pylinton Windows — PASS, was 9 errorspython util/lint.py --black --isort— PASScreate=Trueandas_posix()changes are no-ops whereos.geteuidexists and/is the separator)