Skip to content

fix(pytest): count errors in summary instead of silently dropping them - #2399

Closed
yunancun wants to merge 1 commit into
rtk-ai:developfrom
yunancun:fix/pytest-error-count
Closed

yunancun wants to merge 1 commit into
rtk-ai:developfrom
yunancun:fix/pytest-error-count

Conversation

@yunancun

@yunancun yunancun commented Jun 11, 2026 •

Copy link
Copy Markdown

Summary

  • rtk pytest silently drops pytest error counts: a run ending in 20 passed, 1 error in 1.94s (exit code 1) is summarized as the all-green Pytest: 20 passed. Errors (broken fixtures, setup/teardown errors) are invisible unless the caller checks the exit code and digs into the tee log.
  • Collection errors (Interrupted: 1 error during collection, exit code 2) are reported as Pytest: No tests collected, which is misleading.
  • === ERRORS === detail blocks were never captured by the state machine, so the cause of an error never appeared in the filtered output (and single ERROR ... short-summary entries rendered as empty items).

This fix makes parse_summary_line count N error(s), blocks the all-green short form whenever errors were counted (or any failure detail was collected), captures === ERRORS === sections like FAILURES, and renders ERROR ... short-summary entries with an [ERROR] label.

Reproduction (before → after, rtk built from develop @ 6785a6c)

Broken fixture (pytest exits 1, prints 20 passed, 1 error in 1.94s):

before: Pytest: 20 passed
after:  Pytest: 20 passed, 0 failed, 1 error
        Failures:
        1. [FAIL] ERROR at setup of test_uses_broken
             tests/conftest.py:5: in broken_fixture
             raise RuntimeError("fixture setup exploded")

Collection error (pytest exits 2):

before: Pytest: No tests collected
after:  Pytest: 0 passed, 0 failed, 1 error
        Failures:
        1. [FAIL] ERROR collecting tests/test_s2.py
             ImportError while importing test module ...

Mixed (2 failed, 7 passed, 1 error in 0.02s):

before: Pytest: 7 passed, 2 failed            (error count + detail dropped)
after:  Pytest: 7 passed, 2 failed, 1 error   (all three problems shown)

All-green runs are unchanged (Pytest: 5 passed, byte-identical to before), and exit codes pass through untouched as before.

For agent workflows this matters because the compressed summary is the only thing the LLM reads: an "all passed" line for a run that actually had errors leads the agent to conclude the suite is green ("Correctness VS Token Savings").

Review update: anchored -q bare-summary detection

Adversarial review of the first revision of this PR found a regression it introduced: the -q bare-summary heuristic matched on substrings (contains(" error") … && contains(" in ")), so captured stdout of a failing test containing prose like retrying after error in connection pool was mistaken for the summary line, displacing the real footer and reporting a red run as Pytest: No tests collected.

The same false-capture already exists on develop for the pre-existing passed/failed/skipped arms — stdout prose like worker 3 passed in shard cleanup makes unpatched rtk report a false all-green Pytest: 3 passed (exit 1, zero failure detail shown) for a red run.

This revision replaces the substring checks with a structural matcher (is_bare_summary_line): every comma-separated stat must have the <count> <category> shape and the line must end in in <duration>s (with pytest's optional (h:mm:ss) suffix for runs over 60s). Capture is also last-match-wins instead of first-match-wins — the genuine footer is always the final such line of a pytest run, so even a verbatim inner pytest summary printed by a test that itself drives pytest can no longer pin the summary slot. Both bait shapes (the regression and the pre-existing one) now produce Pytest: 1 passed, 1 failed plus failure detail, matching native pytest.

Test plan

  • cargo fmt --all --check && cargo clippy --all-targets && cargo test — clippy clean, full suite 2157 passed / 0 failed (base before this change: 2150 passed / 0 failed; the +7 are the new tests below)
  • 4 unit tests for error counting in pytest_cmd.rs: test_parse_summary_line_errors (singular/plural/error-only/mixed summary lines), test_filter_pytest_errors_not_collapsed_to_all_green, test_filter_pytest_collection_error, test_filter_pytest_mixed_failures_and_errors — all 4 fail on the unpatched code (verified by reverting the parse branch), pass with the fix
  • 3 unit tests for summary anchoring: test_is_bare_summary_line_anchoring (real footer shapes incl. (h:mm:ss) accepted; stdout prose, ===-wrapped and FAILED ... lines rejected), test_filter_pytest_stdout_prose_not_mistaken_for_summary, test_filter_pytest_verbatim_inner_summary_in_stdout — verified to fail when the anchoring is reverted to substring matching, pass with the fix
  • Manual testing: rtk pytest run against five real scenario repos (broken fixture / import error during collection / mixed pass+fail+error / stdout containing ...error in... prose / stdout containing ...passed in... prose) and one all-green repo, compared side by side with native pytest -q output and exit codes (outputs above)

🤖 Generated with Claude Code

pytest runs that end in errors (broken fixtures, collection errors)
were summarized with no error indication at all:

- "20 passed, 1 error in 1.94s" became "Pytest: 20 passed" — the
  all-green short form — while the exit code stayed 1.
- "Interrupted: 1 error during collection" (exit 2) became
  "Pytest: No tests collected", which is misleading.
- "=== ERRORS ===" detail blocks were never captured, so the cause of
  setup/collection errors was invisible in the filtered output.

Fixes:
- parse "N error(s)" in the summary line (=== wrapped and -q bare forms)
- never take the all-green short form when errors were counted or any
  failure detail was collected
- treat "=== ERRORS ===" sections like FAILURES so error detail blocks
  are preserved
- render short-summary "ERROR ..." entries, which previously rendered
  as empty items
- anchor -q bare summary detection on the full summary grammar
  ("<N> <category>[, ...] in <duration>s") instead of substrings, and
  let the last match win: captured stdout of failing tests flows
  through the same scan, so prose like "retrying after error in
  connection pool" (or a verbatim inner pytest summary printed by a
  test driving pytest itself) must never displace the real footer
@yunancun
yunancun force-pushed the fix/pytest-error-count branch from 8a87a1e to 32561a0 Compare June 11, 2026 18:44
@CLAassistant

CLAassistant commented Jun 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@rtk-release-bot

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet.

@rtk-release-bot

Copy link
Copy Markdown
Contributor

Closing this pull request after a prolonged period of inactivity. If this is still relevant, please ask for it to be reopened. Thank you!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants