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.
This commit is contained in:
2026-06-09 08:08:11 -04:00
parent a31342b478
commit 07e98aab57
+11 -2
View File
@@ -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