Skip to content

Conversation

@CortexShadow
Copy link
Contributor

Summary

This PR fixes an issue where junitxml could drop captured output from the setup and call phases when test reports arrive in an interlaced order. Refs #14078.

Problem

The current interlaced-report handling in junitxml assumes the presence of pytest-xdist-specific report attributes. When reports do not carry those attributes, captured stdout/stderr from setup and call phases may be lost and never written to the final JUnit XML, even when junit_logging is configured to include it.

Fix

Captured output is now buffered per test node and written out once the report sequence completes, ensuring setup and call output is preserved regardless of report ordering. The existing junit_logging behavior and output suppression semantics are unchanged.

Tests

A deterministic regression test was added that replays reports in a fixed interlaced order and asserts that:

  • setup and call output is included when junit_logging=all
  • only stdout is included for system-out
  • only stderr is included for system-err

Tests run:

python -m pytest testing/test_junitxml.py
python -m pytest testing/test_junitxml.py -k interlaced

Notes

The regression test uses internal helpers to keep the scenario deterministic with minimal scaffolding. If preferred, it can be rewritten to avoid internal APIs at the cost of additional complexity.

CortexShadow and others added 5 commits January 1, 2026 23:33
The test reproduces missing setup/call capstdout/capstderr in the JUnit XML when reports are interlaced and only carry phase output. It replays reports in a fixed interlaced order to stay deterministic and asserts system-out/system-err contents for junit_logging=all, system-out, and system-err.

Refs pytest-dev#14078
worker_id/item_index are injected by xdist, so relying on them drops output from other report sources. Track captured output per nodeid (and worker node when present), diffing across phases so setup/call output is preserved and written at teardown. Buffers are cleaned up after teardown and junit_logging gating is unchanged.

Refs pytest-dev#14078
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant