Unit tests fix.

This commit is contained in:
febux 2026-09-02 23:54:54 +03:00
parent 1e051f3730
commit 1add4353db

View file

@ -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