Repository navigation
Conversation
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
📊 Automated PR Analysis
SummaryFixes 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
Linked issues: #4312 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
Protocol-zero-0
left a comment
There was a problem hiding this comment.
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.
|
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. |
Summary
rtk pytestin quiet mode (-q) could report a failing run as passing. The bare-summary branch infilter_pytest_outputonly accepted a line whilesummary_linewas still empty, so the first summary-shaped line won. When a failing test printed something like1 passed in 0.01s, pytest echoed it in the "Captured stdout call" section of the failure block, before the real1 failed in 0.01s. rtk then parsed0 failedandbuild_pytest_summaryreturned early withPytest: 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 -rxXand no xfails there is no "short test summary info" section, so the real bare summary arrives while the parser is still inFailures, and that approach would break the ordinary failing case.Fixes #4312
Test plan
test_filter_pytest_quiet_mode_ignores_summary_lookalike_in_captured_stdout(realistic-q --tb=short -rxXoutput 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 --checkcargo clippy --all-targets(no warnings)cargo test: all pass (3831 unit tests plus all integration test binaries)pytestbinary (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.