Skip to content

fix(pytest): keep a captured banner from opening a failure block - #4802

Open
viniciusdsandrade wants to merge 2 commits into
rtk-ai:developfrom
viniciusdsandrade:fix/4748-pytest-captured-header
Open

viniciusdsandrade wants to merge 2 commits into
rtk-ai:developfrom
viniciusdsandrade:fix/4748-pytest-captured-header

Conversation

@viniciusdsandrade

Copy link
Copy Markdown
Contributor

Summary

  • A line a failing test prints under Captured stdout can match is_block_header (_____ stage one _____, _ stage two _). The parser treated that line as the next failure, so the banner became its own [FAIL] and later captured lines moved into it.
  • After a captured section, only a separator pytest itself prints starts the next block. That separator is the column-0 line from TerminalWriter.sep: _ fills around the title, right fill equal to the left or one longer, at least 39 columns. A shorter banner stays in the capture.
  • Closes rtk pytest: a captured line shaped like a block header (___ x ___, _ x _) opens a phantom [FAIL] entry #4748.

Test plan

  • test_filter_pytest_captured_banner_is_not_a_failure uses the capture from rtk pytest: a captured line shaped like a block header (___ x ___, _ x _) opens a phantom [FAIL] entry #4748 and expects one entry, [FAIL] test_banner, with the location line and the two E lines. stage one, stage two, and E not an error are absent.
  • test_filter_pytest_shortened_header_starts_a_block still opens the second entry on the long _ nodeid _ header, which is outside any captured section.
  • test_filter_pytest_captured_underscore_lines_are_not_headers still splits on the real separator that follows a captured section.
  • Checked by reading filter_pytest_output and the fixtures under tests/fixtures/pytest_*.txt (every existing underscore header there is at least 80 columns and still matches). Formatting, clippy, and tests are left to CI.

`filter_pytest_output` starts a new failure at every line that matches
`is_block_header`. That match is on the trimmed line and runs inside the
captured-stdout section, so a test that prints `_____ stage one _____` or
`_ stage two _` shows up as its own `[FAIL]`.

pytest's own separator is the line `TerminalWriter.sep` prints at column 0:
underscore fills around the title, at least 39 columns. After a captured
section, only that separator ends the block. The next failure still splits
there, and a banner the test printed stays in the capture.
The banner from rtk-ai#4748 is stdout under a Captured section. The filter keeps
the one real failure and its four lines, and drops the phantom entries.
@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working pytest labels Oct 27, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes a pytest output filter bug where a printed banner in captured stdout (matching the loose block-header pattern) was mistakenly treated as the start of a new failure block, causing later captured lines to be misattributed. The fix tracks when the parser is inside a captured section and only treats a line as a new failure header there if it's an actual pytest-generated separator (based on TerminalWriter.sep's fill-width rules).

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4748


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@Protocol-zero-0 Protocol-zero-0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 3e29561874807f438136aefafce12568d1d3b7e6 against e05c7bdf with real pytest 9.0.3 on Linux.

The captured stdout/stderr banners no longer become [FAIL] stage one, [FAIL] stage two, or [FAIL] stderr stage. The next genuine failure still has its own entry, location, and diagnostic. I checked terminal widths 40/41/80/120 with short and long tracebacks, a long parametrized ID, an unescaped Unicode ID, colors, setup-error capture, -s, and a passing control: 15 scenarios / 45 native-base-head executions. The -rA control still shows the baseline's separate PASSES/duplicate-summary problem; #4621 covers that state-transition work. This patch removes the captured-banner entries in that control too.

All 61 pytest parser tests, cargo fmt --all --check, and cargo clippy --locked --offline --all-targets -- -D warnings passed. No blocker found in this change. This was a targeted Linux review; the full suite and other platforms were not run.

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

Labels

bug Something isn't working pytest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk pytest: a captured line shaped like a block header (___ x ___, _ x _) opens a phantom [FAIL] entry

2 participants