From 75c825924bcefdd977cfcb6fc3a75d5bc30e7f97 Mon Sep 17 00:00:00 2001 From: Jeff Smith Date: Sun, 19 Apr 2026 12:00:12 -0600 Subject: [PATCH] test(health): assert healthz_failed log on 503 (#26) --- tests/test_health.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_health.py b/tests/test_health.py index a19ab73..cdb3363 100644 --- a/tests/test_health.py +++ b/tests/test_health.py @@ -1,5 +1,7 @@ from __future__ import annotations +import logging + from sqlalchemy.exc import OperationalError from quartermaster.db import get_session @@ -13,7 +15,7 @@ def test_healthz_returns_ok(client): assert response.json() == {"status": "ok"} -def test_healthz_returns_503_when_db_check_raises(): +def test_healthz_returns_503_when_db_check_raises(caplog): app = create_app() def broken_session(): @@ -32,6 +34,7 @@ def test_healthz_returns_503_when_db_check_raises(): app.dependency_overrides[get_session] = broken_session + caplog.set_level(logging.WARNING, logger="quartermaster.health") with TestClient(app) as client: response = client.get("/healthz") @@ -39,3 +42,8 @@ def test_healthz_returns_503_when_db_check_raises(): body = response.json() assert body["status"] == "error" assert body["detail"] == "OperationalError" + + failed = [r for r in caplog.records if getattr(r, "event", None) == "healthz_failed"] + assert len(failed) == 1 + assert failed[0].levelname == "WARNING" + assert failed[0].error_class == "OperationalError"