Skip to content

fix(ingestion): capture structlog output in pytest caplog - #1029

Open
parker-cassar wants to merge 8 commits into
ascherj:mainfrom
parker-cassar:fix/159-structlog-caplog
Open

fix(ingestion): capture structlog output in pytest caplog#1029
parker-cassar wants to merge 8 commits into
ascherj:mainfrom
parker-cassar:fix/159-structlog-caplog

Conversation

@parker-cassar

Copy link
Copy Markdown

Summary

Wire structlog into stdlib logging for the test suite so pytest's caplog fixture can see application log events. This fixes suite-wide failures where structlog printed warnings to stdout but caplog.text stayed empty (notably test_empty_chunks_list_returns_empty).

Issue

Closes #159

Changes

  • Add an autouse configure_structlog_for_caplog fixture in tests/conftest.py that configures structlog with LoggerFactory, stdlib processors, and ConsoleRenderer, then resets defaults after each test
  • Add tests/unit/test_structlog_caplog.py covering warning and info capture via caplog

Testing

  • Unit tests pass for changed behavior (test_empty_chunks_list_returns_empty and new structlog/caplog tests)
  • Integration tests pass (make test-integration) — not required for this test-only change
  • Linter passes on changed files (ruff check tests/conftest.py tests/unit/test_structlog_caplog.py)
  • Type checker / pre-commit hooks passed on commit
  • New/updated tests cover the changes

Pre-existing failures (unchanged by this PR)

make check and full make test-unit already fail on main for unrelated reasons. Before this change: 55 failed, 375 passed. After: 52 failed, 378 passed (the empty-chunks caplog failure plus the two new tests now pass; remaining failures are pre-existing in bias_detector, faithfulness_checker, pii_scrubber, review_service, etc.). Lint reports ~182 ruff errors and mypy reports ~103 errors across the codebase, none in the files this PR touches.

Screenshots / Demo

N/A (test infrastructure only)

Notes for Reviewers

  • Production logging in core/logging.py is intentionally unchanged
  • cache_logger_on_first_use=False so module-level structlog.get_logger() proxies pick up the test config
  • Please focus review on whether the processor chain is the right test-only approach vs calling configure_logging() directly

Recording issue choice and local setup notes for Module 3.
Documented the failing caplog repro and the intended conftest fix.
Configure structlog with a stdlib LoggerFactory in the test suite so
warning events reach pytest's caplog fixture. Fixes empty-chunks
assertions without changing production logging.

Fixes ascherj#159
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

structlog output is not captured by pytest caplog — log assertions fail suite-wide

1 participant