test(gateway): make test_gateway collectable on Windows
`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
This commit is contained in:
parent
9507f4382e
commit
05504bd9f0
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue