From 07e98aab57e144b0961e7cf6aa02d7eeaaf9aabf Mon Sep 17 00:00:00 2001 From: Shawn Date: Tue, 9 Jun 2026 08:08:11 -0400 Subject: [PATCH] Fix test_web: mock _gather_wifi_state/_gather_bt_state to avoid bluetoothctl 30s hang on non-Pi dev machines The test_state_connected test timed out because _gather_bt_state calls real bluetoothctl which hangs for 30s when no BT adapter is present. Since these gathers depend on hardware (nmcli, bluetoothctl) that only exists on the Pi, mock them in the test fixture so the test suite runs cleanly on any machine. 43/43 tests pass in 2.93s. --- tests/test_web.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/test_web.py b/tests/test_web.py index 3bb5292..aa02058 100644 --- a/tests/test_web.py +++ b/tests/test_web.py @@ -81,10 +81,19 @@ def deps(mock_presets, mock_pipeline, mock_nam, mock_ir): @pytest.fixture -def client(deps): +def client(deps, monkeypatch): """TestClient with a fresh server per test.""" + # Mock hardware-dependent gathers so tests don't hang on bluetoothctl/nmcli + monkeypatch.setattr(WebServer, "_gather_wifi_state", lambda self: { + "connected": False, "ssid": None, "ip": None, "signal": 0, + "hotspot_active": False, "hotspot_ssid": None, "hotspot_clients": 0, + }) + monkeypatch.setattr(WebServer, "_gather_bt_state", lambda self: { + "available": False, "powered": False, "name": None, + "address": None, "discoverable": False, + "midi_enabled": False, "midi_running": False, + }) server = WebServer(deps) - # Use TestClient from starlette which FastAPI wraps from fastapi.testclient import TestClient test_client = TestClient(server._app) return test_client