Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

fix(tests): reset whole headroom logger subtree so caplog stays deterministic (#1117)

Zhenjia ZHOUfda4670ef8a8
diff --git a/tests/conftest.py b/tests/conftest.py
index 62519e4c5..54c0b188b 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -44,26 +44,30 @@ def pytest_runtest_call(item):
def _reset_headroom_logger_propagation():
"""Keep `headroom.*` log records flowing to pytest's caplog handler.
- `headroom.proxy.helpers._setup_file_logging` sets
- ``logging.getLogger("headroom").propagate = False`` once any test
- triggers a proxy startup with `--log-file`. After that, every
- subsequent test's `caplog` fixture stops capturing `headroom.*`
- log records (caplog attaches to root, propagation is now blocked
- at the headroom-logger boundary). Reset before every test so the
- capture is deterministic regardless of run order.
+ Two sources disable propagation on the headroom logger tree and never
+ restore it, which then makes later `caplog`-based assertions flaky in
+ full-suite runs (caplog attaches to root, so a `propagate=False` anywhere
+ on the chain silently drops the records):
+
+ - ``headroom.proxy.helpers._setup_file_logging`` sets
+ ``getLogger("headroom").propagate = False`` on proxy startup.
+ - ``benchmarks.claude_session_mode_benchmark._disable_headroom_benchmark_logging``
+ (exercised by ``test_claude_session_mode_benchmark``) sets
+ ``propagate = False`` + ``CRITICAL`` on ``headroom``, ``headroom.proxy``,
+ ``headroom.transforms``, ``headroom.cache`` (and children).
+
+ Resetting only ``"headroom"`` is not enough — a child like
+ ``"headroom.proxy"`` left non-propagating blocks the record before it
+ reaches root. Reset the whole subtree before every test so capture is
+ deterministic regardless of run order.
"""
import logging as _logging
- for logger_name in (
- "headroom",
- "headroom.proxy",
- "headroom.proxy.forwarded_headers",
- "headroom.transforms",
- "headroom.transforms.kompress_compressor",
- ):
- logger = _logging.getLogger(logger_name)
- logger.disabled = False
- logger.propagate = True
+ for _name in ("headroom", *list(_logging.root.manager.loggerDict)):
+ if _name == "headroom" or _name.startswith("headroom."):
+ logger = _logging.getLogger(_name)
+ logger.disabled = False
+ logger.propagate = True
yield