From 9561c80d234e8d898858424d397b32790db82938 Mon Sep 17 00:00:00 2001 From: hyqqx <174831728+hyqqx@users.noreply.github.com> Date: Wed, 29 Jul 2026 16:09:40 +0300 Subject: [PATCH] fix(tests): don't assert host-OS state in the IS_WINDOWS=False no-op 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 --- tests/test_windows_subprocess_no_window_flags.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/test_windows_subprocess_no_window_flags.py b/tests/test_windows_subprocess_no_window_flags.py index 0dcf29405ba4c..09e9df2923fcf 100644 --- a/tests/test_windows_subprocess_no_window_flags.py +++ b/tests/test_windows_subprocess_no_window_flags.py @@ -1059,8 +1059,9 @@ def fake_run(cmd, **kwargs): def test_suppress_platform_ver_console_posix_noop(monkeypatch): - """On POSIX the helper must do nothing at all and never raise.""" + """With IS_WINDOWS off, the helper must do nothing at all and never raise.""" import platform + import sys from hermes_cli import _subprocess_compat @@ -1070,8 +1071,15 @@ def test_suppress_platform_ver_console_posix_noop(monkeypatch): _subprocess_compat.suppress_platform_ver_console() assert platform._syscmd_ver is original - # win32_ver stays functional (returns empty fields off Windows). - assert platform.win32_ver() == ("", "", "", "") + # win32_ver stays functional — the helper must not have broken it. + version = platform.win32_ver() + assert isinstance(version, tuple) and len(version) == 4 + # The emptiness of those fields is a property of the *host* OS, not of the + # helper: off Windows they are blank, on a real Windows host they carry the + # actual release. monkeypatching IS_WINDOWS does not change what + # platform.win32_ver() reads, so only assert emptiness where it holds. + if sys.platform != "win32": + assert version == ("", "", "", "") def test_suppress_platform_ver_console_stubs_syscmd_ver(monkeypatch):