File size: 934 Bytes
700e896
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""Structured logging — step() works, and silence mode (RERANKER_LOG=0) doesn't crash."""

from __future__ import annotations

import pytest

from common import logging as logging_module
from common.logging import step


def test_step_yields_metrics_and_runs() -> None:
    with step("test.stage", rows_in=3) as metrics:
        metrics["rows_out"] = 3
    assert metrics["rows_out"] == 3


def test_silence_mode_does_not_crash(monkeypatch: pytest.MonkeyPatch) -> None:
    # RERANKER_LOG=0 must filter cleanly — structlog rejects non-standard levels (CRITICAL+1 → KeyError).
    monkeypatch.setenv("RERANKER_LOG", "0")
    try:
        logging_module._configure_logging(force=True)
        with step("test.silence") as metrics:
            metrics["ok"] = True
    finally:
        monkeypatch.delenv("RERANKER_LOG", raising=False)
        logging_module._configure_logging(force=True)  # restore normal config for other tests