Skip to content

fix(pytest): take the last summary line as the session summary - #4374

Closed
Cedric921 wants to merge 1 commit into
rtk-ai:developfrom
Cedric921:fix/pytest-last-summary-wins
Closed

Cedric921 wants to merge 1 commit into
rtk-ai:developfrom
Cedric921:fix/pytest-last-summary-wins

Conversation

@Cedric921

Copy link
Copy Markdown
Contributor

Summary

rtk pytest in quiet mode (-q) could report a failing run as passing. The bare-summary branch in filter_pytest_output only accepted a line while summary_line was still empty, so the first summary-shaped line won. When a failing test printed something like 1 passed in 0.01s, pytest echoed it in the "Captured stdout call" section of the failure block, before the real 1 failed in 0.01s. rtk then parsed 0 failed and build_pytest_summary returned early with Pytest: 1 passed, dropping the failure details.

Fix: let the last match win. pytest always prints the real session summary last, so a later summary-shaped line replaces an earlier one.

I did not go with the alternative of only accepting the summary outside ParseState::Failures. With -q -rxX and no xfails there is no "short test summary info" section, so the real bare summary arrives while the parser is still in Failures, and that approach would break the ordinary failing case.

Fixes #4312

Test plan

  • New regression test test_filter_pytest_quiet_mode_ignores_summary_lookalike_in_captured_stdout (realistic -q --tb=short -rxX output with a lookalike line in captured stdout). It failed before the fix (Pytest: 1 passed in 0.01s) and passes after it.
  • cargo fmt --all --check
  • cargo clippy --all-targets (no warnings)
  • cargo test: all pass (3831 unit tests plus all integration test binaries)
  • Not run against a real pytest binary (not installed on this machine); the regression test uses the raw output shape from the issue's repro.

Side effect, for review: a summary-shaped line inside captured stdout is now taken as a summary candidate and no longer appears in the rendered failure block. Before this change that already happened to any such line printed after the first one.

In quiet mode (-q) the bare summary branch kept the first line that looked
like a summary. A failing test that printed e.g. "1 passed in 0.01s" to
stdout had that line captured in its failure block, so it won over pytest's
real "1 failed in 0.01s": the run was reported green and the failure block
was dropped. The real session summary is always the last such line, so let
the last match win.

Fixes rtk-ai#4312
@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working pytest regression-test labels Oct 1, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes a bug in rtk's pytest output filter where a summary-shaped line appearing earlier in captured stdout (e.g. inside a failure's 'Captured stdout call' section) would be mistakenly used as the session summary instead of the real, later-printed summary line. The fix changes the bare-summary match to let the last matching line win, since pytest always prints the true summary last, and adds a regression test covering this scenario.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4312


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.

Independently validated this fix against its own parent 4c8a255 and head eb24bf2 with real pytest 9.0.3 on Linux.

Eight cases / 24 raw-parent-head executions cover captured lookalikes for passed, failed and skipped counts, a mixed 1-passed/1-failed/1-skipped session, a real nested pytest subprocess, plain failing/passing controls, and -ra reporting. The parent reports 99 passed for an actual one-failure session (and the inner 1 passed for the nested run); this head reports the outer 0 passed, 1 failed and retains the assertion failure details. The mixed counts are also correct. All runs preserve the producer exit code: 1 on failures and 0 for the passing control.

The -ra case still needs this fix: enabling the short test summary section does not prevent the parent's earlier captured lookalike from winning. Both versions built with cargo build --locked --offline; all 14 targeted pytest_cmd::tests passed on the head.

The documented side effect is visible: summary-shaped captured stdout is consumed rather than kept as a diagnostic line. This approval covers selection of the actual outer session summary for the tested output shapes and #4312; it does not establish behavior for arbitrary plugin output after the final summary. I did not run the full suite, clippy, or cross-platform tests.

@KuSh

KuSh commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Thanks @Cedric921, the approach here was right: take the last summary-shaped line, because pytest prints the real session summary last. #3355, merged in ebf5f71, makes the same change, so I'm closing this as a duplicate of #3355. Your test from this PR passes unchanged on #3355's parser, and #3355 has its own test for the captured-stdout case from #4312.

@KuSh KuSh closed this Oct 19, 2026
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 regression-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pytest filter takes a captured-stdout lookalike (1 passed in 0.01s printed by a test) as the session summary, so a failing run reads green

3 participants