Skip to content

fix(pytest): report setup errors in the summary - #4466

Merged
KuSh merged 1 commit into
rtk-ai:developfrom
Cedric921:fix/pytest-error-count
Oct 19, 2026
Merged

KuSh merged 1 commit into
rtk-ai:developfrom
Cedric921:fix/pytest-error-count

Conversation

@Cedric921

Copy link
Copy Markdown
Contributor

Summary

A pytest run with fixture, teardown or collection errors ends with 1 passed, 1 error in 0.02s (exit 1), but rtk pytest printed Pytest: 1 passed in 0.02s, so a failing run looked fully green. Three changes in src/cmds/python/pytest_cmd.rs fix this:

  • parse_summary_line now counts error / errors, and build_pytest_summary no longer takes the all-green branch when errors are present. The summary line uses the existing multi-count form plus pytest's singular/plural noun: Pytest: 1 passed, 0 failed, 1 error in 0.02s.
  • The === ERRORS === section now feeds the same block collection as === FAILURES ===. Its ___ ERROR at setup of test_e ___ / ___ ERROR collecting test_bad.py ___ headers render as [ERROR] at setup of test_e / [ERROR] collecting test_bad.py, followed by the same up-to-3 relevant traceback lines as failures.
  • ERROR <nodeid> - <msg> short-summary lines (printed with -rE / -ra) were already collected but rendered as empty entries. They now render like FAILED lines, tagged [ERROR].

Output for the repro in the issue:

Pytest: 1 passed, 0 failed, 1 error in 0.02s

Failures:
1. [ERROR] at setup of test_e
     test_e.py:3: in boom
     def boom(): raise RuntimeError("fixture")
     E   RuntimeError: fixture

Not changed: summary-line detection. A run where every test errors (2 errors in 0.03s, with no passed/failed/skipped) is still not recognised as a summary. It still falls back to the raw output, because the exit code is non-zero and the filter result is "No tests collected", so nothing is hidden. Widening detection would conflict with #4374 and #3355, which both rewrite those lines. (#3355's summary regex already accepts errors?, so combined with this PR that case would also render compactly.) This PR also does not overlap #4374 (last-summary-wins); both can merge in either order.

Fixes #4426

Test plan

  • New tests fail on develop (Pytest: 1 passed in 0.02s, Pytest: 1 passed, 1 failed in 0.05s, …) and pass with the fix:
    • test_filter_pytest_fixture_error_is_reported: the issue's pytest 9.1.1 -q --tb=short -rxX output
    • test_filter_pytest_errors_and_failures_together: setup and teardown errors plus a failure, 2 errors plural
    • test_filter_pytest_collection_error_is_reported: --continue-on-collection-errors shape
    • test_filter_pytest_error_short_summary_line: ERROR nodeid - msg line from -rE/-ra
    • test_parse_summary_line_errors
  • cargo fmt --all --check
  • cargo clippy --all-targets (zero warnings)
  • cargo test (all pass)
  • Real pytest run: not done locally (pytest isn't installed). The fixtures follow the raw output quoted in the issue and pytest 9's -q --tb=short ERRORS layout.

A run with fixture, teardown or collection errors ended "1 passed,
1 error" (exit 1) but rtk printed "Pytest: 1 passed": the summary
parser had no arm for error(s) and the ERRORS section was skipped.
Count errors, keep the run off the all-green line, and render the
ERRORS blocks and ERROR short-summary lines as [ERROR] entries.

Fixes rtk-ai#4426
@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added area:cli bug Something isn't working pytest labels Oct 6, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes the pytest filter so runs with setup/teardown/collection errors are no longer reported as fully green. parse_summary_line now counts errors, the ERRORS section feeds the same failure-block rendering as FAILURES, and ERROR short-summary lines render like FAILED lines instead of empty entries.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4426


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 cdad612 against eb225a1 with real pytest 9.0.3, including the CLI exit status. I reproduced the original bug on the base: exit 1, but output Pytest: 1 passed in ... with the fixture error hidden. The PR head reports the error count and traceback correctly.

Actual pytest runs on the head:

Case Compact result Raw / RTK exit
Setup error + passing test 1 passed, 0 failed, 1 error 1 / 1
Teardown error + passing test 2 passed, 0 failed, 1 error 1 / 1
Setup + teardown errors + assertion failure 2 passed, 1 failed, 2 errors 1 / 1
Collection error with --continue-on-collection-errors 1 passed, 0 failed, 1 error 1 / 1
Setup error with -rE Error block and ERROR nodeid both present 1 / 1
Two errors, no passing tests Raw fallback retains both errors and traceback 1 / 1
Passing test only 1 passed 0 / 0

The 18 pytest-filter unit tests also passed. I did not find a blocking issue in the changed error-handling path. The errors-only fallback behaves as described in the PR, so widening summary detection can remain separate.

Small reproduction for the setup case:

import pytest

@pytest.fixture
def boom():
    raise RuntimeError("fixture")

def test_error(boom): pass
def test_ok(): pass

Run in a directory containing that file as test_case.py:

pytest -q --tb=short -rxX
rtk pytest -q --tb=short -rxX

Both should exit 1; the RTK output should retain 1 error and RuntimeError: fixture.

@Protocol-zero-0

Copy link
Copy Markdown
Contributor

I checked this alongside #4374 because both change src/cmds/python/pytest_cmd.rs. A synthetic merge of the two current heads is conflict-free, and the combined pytest_cmd::tests suite passes (19 tests). The cases cover both the real session summary winning over captured-output lookalikes and setup/teardown/collection errors appearing in the summary.

The current develop is a4cddfc5; this branch is 42 commits behind and diverged from it, while #4374 is also still open. Suggested landing order: merge/rebase #4374 first, then rebase this branch on the resulting develop and rerun the focused tests. That keeps the two fixes together while leaving the final merge decision with maintainers.

@Protocol-zero-0

Copy link
Copy Markdown
Contributor

Updating my earlier integration-order recommendation with new evidence: #3355 now has b4c642c, addressing the previously outstanding parser review. I independently verified that head plus this PR, including a fixture-only error that prints a captured fake-success summary: the combined output is correctly 0 passed, 0 failed, 1 error, with the exception retained. #4374 + this PR still shows 99 passed for that case.

I recommend #3355 first, followed by rebasing this PR onto it for error counts. The combined tree applies cleanly and passes full local checks; review and precise validation scope: #3355 (review). The no-stats-line -qq case remains tracked separately in #2960. Final selection and merge remain with the maintainers.

@aeppling aeppling 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.

Checked against real pytest 7.4.4, 8.0.2 and 9.1.1: setup, teardown and collection errors are now counted and shown as [ERROR] blocks, and exit codes match raw pytest everywhere. On 1,500 fuzzed runs it lowers runs with a missing error count from 546 to 11.

The only regressions are in -qq, where pytest prints no result line and a test printing 1 passed, 1 error gets picked up as the summary. That's the #2960 family, and it's fixed separately.

Nits, not blocking: the two new comments can go, and with -ra each error is listed twice.

Thanks @Cedric921, and @Protocol-zero-0 for the review. Approving. Best merged after #3355.

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

Labels

area:cli bug Something isn't working pytest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk pytest drops the error count: a run with a fixture error renders Pytest: 1 passed

4 participants