From 50ad191a8b05e8af0a8ee99021633a9d404192d6 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Mon, 8 Jun 2026 22:54:25 -0700 Subject: [PATCH] test(hermes_cli): harden concurrent-gate fixture against partial-import race (#42626) The autouse _suppress_concurrent_hermes_gate fixture did monkeypatch.setattr(main, '_detect_concurrent_hermes_instances', ...) with no raising=False. Its try/except guards the import but not the setattr, so under pytest's per-test spawn isolation a transiently partial hermes_cli.main module (one a concurrent worker is mid-importing) made setattr raise AttributeError and errored unrelated tests in the slice. Add raising=False so a transiently-absent attribute is a no-op default rather than a hard error. The attribute always exists once main.py finishes importing; the real-function opt-out (@pytest.mark.real_concurrent_gate) is unaffected. --- tests/hermes_cli/conftest.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/hermes_cli/conftest.py b/tests/hermes_cli/conftest.py index 3eee1b2f32f2a..2848a8a9aa238 100644 --- a/tests/hermes_cli/conftest.py +++ b/tests/hermes_cli/conftest.py @@ -41,6 +41,16 @@ def _suppress_concurrent_hermes_gate(request, monkeypatch): from hermes_cli import main as _cli_main except Exception: return + # raising=False: under pytest's per-test spawn isolation, a concurrent + # xdist worker importing a module that transitively touches hermes_cli.main + # can briefly expose a partially-initialized module object here — one where + # _detect_concurrent_hermes_instances isn't defined yet. A bare setattr + # would raise AttributeError and error the (unrelated) test. The attribute + # always exists once main.py finishes importing, so a no-op when it's + # transiently absent is the correct, race-free default. monkeypatch.setattr( - _cli_main, "_detect_concurrent_hermes_instances", lambda *_a, **_k: [] + _cli_main, + "_detect_concurrent_hermes_instances", + lambda *_a, **_k: [], + raising=False, )