From 1add4353db47bed26b5414fd2d3634eeb80df38c Mon Sep 17 00:00:00 2001 From: febux Date: Wed, 2 Sep 2026 23:54:54 +0300 Subject: [PATCH] Unit tests fix. --- tests/unit/test_http_logging.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/unit/test_http_logging.py b/tests/unit/test_http_logging.py index 23e35cc..57476b7 100644 --- a/tests/unit/test_http_logging.py +++ b/tests/unit/test_http_logging.py @@ -11,6 +11,7 @@ import json import httpx import pytest +import structlog from structlog.testing import capture_logs from contract_check.core import http_logging as hhttp @@ -85,6 +86,22 @@ async def test_event_hooks_log_request_and_response_payloads( monkeypatch: pytest.MonkeyPatch, ) -> None: monkeypatch.setattr(hhttp, "is_debug_enabled", lambda: True) + # Other tests may configure structlog with a filtering wrapper at INFO, + # which causes ``capture_logs`` to drop DEBUG records. Reconfigure to a + # non-filtering wrapper so the DEBUG http_request/http_response events are + # always captured. + _config = structlog.get_config() + monkeypatch.setattr( + hhttp, + "get_logger", + lambda name: structlog.get_logger(name), + ) + structlog.configure( + processors=_config["processors"], + wrapper_class=structlog.stdlib.BoundLogger, + logger_factory=_config["logger_factory"], + cache_logger_on_first_use=False, + ) with capture_logs() as logs: transport = httpx.MockTransport( lambda request: httpx.Response(200, json={"ok": True, "token": "jwt-secret"}) # noqa: S106