- test_setup_logging_emits_json_when_LOG_JSON_true - test_correlation_id_middleware_binds_contextvar - test_correlation_id_response_header_present - test_contextvars_cleared_between_requests (Pitfall 2 guard) - test_uvicorn_access_log_suppressed All strict=False xfail stubs; implementation target: plan 06-02
53 lines
2.2 KiB
Python
53 lines
2.2 KiB
Python
"""
|
|
Structured logging test stubs — D-01, D-02.
|
|
|
|
Wave 0 xfail scaffold for Phase 6 plan 06-02.
|
|
|
|
All tests use strict=False so an unexpected pass during development
|
|
never breaks CI. Implementation lands in plan 06-02.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
|
|
# ── D-01: JSON renderer wired through ProcessorFormatter ─────────────────────
|
|
|
|
@pytest.mark.xfail(strict=False, reason="implementation in 06-02")
|
|
async def test_setup_logging_emits_json_when_LOG_JSON_true():
|
|
"""setup_logging(json_logs=True) installs JSONRenderer through
|
|
ProcessorFormatter and the root logger emits JSON to stdout."""
|
|
pytest.xfail("not implemented yet")
|
|
|
|
|
|
# ── D-02: CorrelationIDMiddleware binds structlog contextvars ─────────────────
|
|
|
|
@pytest.mark.xfail(strict=False, reason="implementation in 06-02")
|
|
async def test_correlation_id_middleware_binds_contextvar(async_client):
|
|
"""CorrelationIDMiddleware binds correlation_id, path, and method into
|
|
structlog.contextvars for every inbound HTTP request."""
|
|
pytest.xfail("not implemented yet")
|
|
|
|
|
|
@pytest.mark.xfail(strict=False, reason="implementation in 06-02")
|
|
async def test_correlation_id_response_header_present(async_client):
|
|
"""Every HTTP response includes an X-Correlation-ID header set to the
|
|
correlation_id bound by CorrelationIDMiddleware."""
|
|
pytest.xfail("not implemented yet")
|
|
|
|
|
|
@pytest.mark.xfail(strict=False, reason="implementation in 06-02")
|
|
async def test_contextvars_cleared_between_requests(async_client):
|
|
"""Pitfall 2 guard: clear_contextvars() runs first in the middleware so
|
|
user_id from a prior request never bleeds into the next request's log context."""
|
|
pytest.xfail("not implemented yet")
|
|
|
|
|
|
# ── D-01 / uvicorn log suppression ───────────────────────────────────────────
|
|
|
|
@pytest.mark.xfail(strict=False, reason="implementation in 06-02")
|
|
async def test_uvicorn_access_log_suppressed():
|
|
"""uvicorn.access propagate=False after setup_logging() so the
|
|
CorrelationIDMiddleware owns request logging and access lines are not doubled."""
|
|
pytest.xfail("not implemented yet")
|