Skip to content

Report failures before the pytest hard-exit#24

Open
aleksUIX wants to merge 1 commit into
IABTechLab:mainfrom
aleksUIX:report-failures-before-hard-exit
Open

Report failures before the pytest hard-exit#24
aleksUIX wants to merge 1 commit into
IABTechLab:mainfrom
aleksUIX:report-failures-before-hard-exit

Conversation

@aleksUIX

@aleksUIX aleksUIX commented Jul 6, 2026

Copy link
Copy Markdown

Summary

Any failing test run currently produces a bare F and exit code 1 with zero diagnostics, locally and in CI logs. The os._exit shutdown workaround in tests/conftest.py fires before pytest prints the FAILURES section, and it also drops buffered output. This PR keeps the workaround (the chromadb/posthog atexit hang it dodges is real) while restoring failure reporting.

Before / after

Before, on a clean checkout (pytest tests/unit/test_openrtb_parser.py -q):

........F....                                                            [100%]

That is the entire output. After:

........F....                                                            [100%]
=================================== FAILURES ===================================
____________________ test_round_trip_builder_then_parser_recovers_refs ____________________
...
E               RuntimeError: Could not locate ad_seller_system in path ancestry ...
=========================== short test summary info ============================
FAILED tests/unit/test_openrtb_parser.py::test_round_trip_builder_then_parser_recovers_refs
1 failed, 12 passed in 0.09s

Why two changes

  1. Hook placement: the terminal reporter prints FAILURES, short summary, and the stats line after the non-wrapper pytest_sessionfinish hooks run, so hard-exiting there kills reporting. The exit now happens in pytest_unconfigure, which fires after all reporting; pytest_sessionfinish only records the exit status.
  2. Flush before os._exit: os._exit skips stdio flushing, so with block-buffered output (file redirect, CI log capture) the report was lost even with correct hook order. Both streams are flushed first.

Verification

The failing test shown above is a separate fresh-clone issue; a follow-up PR ports the skip pattern buyer merged in buyer-agent#92.

The os._exit workaround for the chromadb/posthog atexit shutdown
hang (ar-r82f.21) lived in pytest_sessionfinish, which runs before
the terminal reporter prints the FAILURES section, short summary,
and stats line. Every failing run ended with a bare F and no
diagnostics, locally and in CI logs.

Two changes preserve the workaround while restoring reporting:
- record the exit status in pytest_sessionfinish and hard-exit from
  pytest_unconfigure instead, which fires after all reporting
- flush stdout/stderr before os._exit, since it skips stdio
  flushing and block-buffered output (file redirects, CI logs)
  otherwise loses the report even when the hook order is right

Exit status propagation is unchanged. Full unit suite completes in
about 6 seconds with no shutdown hang.
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.

1 participant