fix(tests): don't assert host-OS state in the IS_WINDOWS=False no-op test - #74220
fix(tests): don't assert host-OS state in the IS_WINDOWS=False no-op test#74220hyqqx wants to merge 1 commit into
Conversation
…test
test_suppress_platform_ver_console_posix_noop monkeypatches
_subprocess_compat.IS_WINDOWS to False and checks that
suppress_platform_ver_console() then does nothing. That part is sound and
platform-independent.
Its last line, however, asserts platform.win32_ver() == ("", "", "", ""),
which reads the real host OS. monkeypatching IS_WINDOWS does not change
what platform.win32_ver() reports, so on a native Windows host the test
fails on a fact about the machine rather than about the helper:
E AssertionError: assert ('10', '10.0.26200', 'SP0', 'Multiprocessor Free')
== ('', '', '', '')
This is the pitfall CONTRIBUTING's "Testing cross-platform" section calls
out: patching one platform signal while another re-reads the real OS
independently leaves the test routing through the wrong branch on a
Windows runner.
Keep the behavioural assertion on every platform -- win32_ver() must still
be callable and still return a 4-tuple, which is what proves the helper did
not damage it -- and gate only the emptiness check, which is true off
Windows and false on it.
Verified on native Windows 11 (build 26200), Python 3.11.6:
before, this file reported 39 passed / 1 failed; after, 40 passed.
The behaviour on POSIX is unchanged: the emptiness assertion still runs
there exactly as before.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Native Windows 11 status (monerostar)Quick live check on Windows 11 Pro Build 26200 / Python 3.11.15. Finding: PR target test no longer exists on
|
|
Thanks for identifying the native-Windows test failure. The proposed assertion change was sound while this test existed. Automated hermes-sweeper review found that the PR is already superseded on current
|
What does this PR do?
test_suppress_platform_ver_console_posix_noopfails on a native Windows host — notbecause the code under test is wrong, but because the test asserts a fact about the
machine it runs on.
The test monkeypatches
_subprocess_compat.IS_WINDOWStoFalseand verifies thatsuppress_platform_ver_console()then leavesplatform._syscmd_veruntouched. That partis sound and platform-independent, and it is the actual contract being tested.
The final line is different in kind:
platform.win32_ver()reads the real OS.Monkeypatching
IS_WINDOWSdoes not change what it reports, so on Windows the assertioncompares the host's genuine version tuple against the blanks you get on Linux.
This is precisely the pitfall CONTRIBUTING's Testing cross-platform section warns
about:
The change
Keep the behavioural assertion on every platform —
win32_ver()must still becallable and still return a 4-tuple, which is what actually proves the helper did not
damage it — and gate only the emptiness check, which holds off Windows and cannot hold on
it.
POSIX behaviour is unchanged: the emptiness assertion still runs there exactly as before.
No production code is touched.
How to test
On native Windows:
Before:
39 passed, 1 failedAfter:
40 passedOn Linux/macOS the file is unaffected — the added branch is simply taken.
Why CI never caught this
All CI jobs run on
ubuntu-latest(the onlymatrix.runnervalue in the tree isubuntu-24.04-arm, indocker.yml). There is no Windows runner, so a test that asserts"we are not on Windows" always passes in CI and only fails for contributors actually
developing on the platform.
Platforms tested
Native Windows 11 Home, build 26200 · Python 3.11.6.
Related
Same family, different files, already covered elsewhere — deliberately not duplicated
here:
test_no_op_on_posixandtest_getattr_fallback_prefers_sigkill_when_presentin
tests/tools/test_windows_native_support.py.which-based collection error intests/tools/test_search_hidden_dirs.py.To my knowledge no open PR touches
tests/test_windows_subprocess_no_window_flags.py.