Skip to content

The agent that grows with you

test(gateway): stub psutil in the ps-fallback cmdline test

unsupportedpastels3529aa07e9a9
diff --git a/tests/gateway/test_status.py b/tests/gateway/test_status.py
index d0ba3d3673e..b55fd9549a1 100644
--- a/tests/gateway/test_status.py
+++ b/tests/gateway/test_status.py
@@ -2,6 +2,7 @@
import json
import os
+import sys
import threading
import time
from pathlib import Path
@@ -1369,6 +1370,12 @@ class TestReadProcessCmdlinePsFallback:
def test_ps_fallback_when_proc_unavailable(self, monkeypatch):
monkeypatch.setattr(status.Path, "read_bytes", lambda self: (_ for _ in ()).throw(FileNotFoundError))
+ # psutil sits between /proc and ps; left real, it reads whatever process holds this pid on the
+ # host (CI saw `/usr/sbin/haveged` at 873) and ps is never reached.
+ def _no_such_process(pid):
+ raise ProcessLookupError(pid)
+
+ monkeypatch.setitem(sys.modules, "psutil", SimpleNamespace(Process=_no_such_process))
monkeypatch.setattr(
status.subprocess, "run",
lambda args, **kwargs: SimpleNamespace(returncode=0, stdout="/usr/libexec/bluetoothuserd\n"),