From 05504bd9f090e1825ce08d4ddd10ab9a7edf75d4 Mon Sep 17 00:00:00 2001 From: iso2kx <8766057+iso2kx@users.noreply.github.com> Date: Thu, 30 Jul 2026 13:32:37 +0800 Subject: [PATCH] test(gateway): make test_gateway collectable on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `import pty` at module scope pulls in `termios`, which does not exist on Windows. That raised ModuleNotFoundError during *collection*, so pytest aborted the whole module with Interrupted: 1 error during collection before any skip marker could take effect. The single PTY-dependent test was already correctly marked `skipif(sys.platform == "win32")` — the import crashed ahead of it and took the module's 13 other, entirely platform-agnostic tests down as collateral. Windows contributors got zero gateway coverage and, worse, a collection error that masks real failures in any batch that includes this file. Two changes: - Move `import pty` into the `stdin_is_tty` branch that actually uses it (the sole `pty.openpty()` call). Nothing else in the module needs it. - Skip `test_systemd_install_checks_linger_status` on Windows. It drives `_systemd_linger_enabled()` -> `os.getuid()`, which does not exist on Windows; the production helper is annotated "windows-footgun: ok — POSIX systemd helper, never invoked on Windows", so the test is Linux-only by nature. It was previously hidden behind the collection crash. POSIX behaviour is unchanged: both guards are `skipif(win32)`, inactive off Windows, and the local import resolves exactly where the module-level one did. before (Windows): 0 collected, 1 collection error after (Windows): 14 collected, 9 passed, 5 skipped --- tests/hermes_cli/test_gateway.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/hermes_cli/test_gateway.py b/tests/hermes_cli/test_gateway.py index 5392b951dac06..f6ffd3d51ffa0 100644 --- a/tests/hermes_cli/test_gateway.py +++ b/tests/hermes_cli/test_gateway.py @@ -2,7 +2,6 @@ import argparse import os -import pty import signal import subprocess import sys @@ -111,6 +110,13 @@ def test_gateway_run_subprocess_preserves_daemon_exit_codes( master_fd = slave_fd = None try: if stdin_is_tty: + # Imported here, not at module scope: ``pty`` pulls in ``termios``, + # which does not exist on Windows, so a top-level import raises + # ModuleNotFoundError during *collection* — before the skipif above + # can take effect — and takes the whole module's Windows-viable + # tests down with it. + import pty + master_fd, slave_fd = pty.openpty() stdin = slave_fd else: @@ -219,6 +225,10 @@ class TestContainerSystemdSupport: +@pytest.mark.skipif( + sys.platform == "win32", + reason="systemd user-linger is Linux-only (drives os.getuid())", +) def test_systemd_install_checks_linger_status(monkeypatch, tmp_path, capsys): unit_path = tmp_path / "systemd" / "user" / "hermes-gateway.service"