Skip to content

fix(pytest): pass --version through unfiltered#2141

Open
maxmilian wants to merge 1 commit into
rtk-ai:developfrom
maxmilian:fix/pytest-version-flag-passthrough
Open

fix(pytest): pass --version through unfiltered#2141
maxmilian wants to merge 1 commit into
rtk-ai:developfrom
maxmilian:fix/pytest-version-flag-passthrough

Conversation

@maxmilian
Copy link
Copy Markdown

Summary

Root cause

pytest --version prints its banner and exits without running a test session, so filter_pytest_output finds no passed/failed/skipped summary line. build_pytest_summary then hits the all-zero-counts branch (src/cmds/python/pytest_cmd.rs:183) and returns the hardcoded "Pytest: No tests collected" — the real banner is discarded. (The reporter's "wrapper consumes the flag" hypothesis is close; the flag is forwarded, but the filter swallows the response.)

Fix

In run(), detect --version before flag injection and forward the command with an identity filter (no -q/--tb=short/-rxX injection, no compression), so pytest's output reaches the caller byte-for-byte. Honors RTK design principle #1 (Correctness over Token Savings): a flag that explicitly asks for informational output must not be reformatted into a lossy summary.

Scope (deliberately narrow)

  • --version only. -V/-VV are version-dependent — pytest 9's bare -V runs a full session, so treating it as informational would dump a raw, unfiltered test run (a regression). Encoding that fragile per-version behavior isn't worth it; --version is the reported, unambiguous case.
  • --help/-h are out of scope: clap intercepts them at the subcommand layer and prints rtk's own wrapper help — they never reach run().
  • --collect-only/--co left untouched — already addressed by fix(pytest): handle --collect-only output correctly #925.

Tests

  • test_version_banner_swallowed_by_filter — documents the buggy filter behavior (banner → "No tests collected").
  • test_is_informational_flag--version matches; -V, -VV, --help, -h, -v, --verbose, --collect-only, and test paths do not.
  • Full suite: 1948 passed, clippy clean, cargo fmt --check clean.

Manual verification

$ rtk pytest --version          # before: "Pytest: No tests collected"
pytest 9.0.3                    # after: real version
$ rtk pytest -V                 # still filtered (no regression)

`rtk pytest --version` returned "Pytest: No tests collected": pytest prints
its version banner and exits without a test session, so the summary parser
found no count and build_pytest_summary collapsed the banner to the terse
no-tests message — the real version never reached the caller.

Route --version around the filter and forward pytest's output verbatim.
Scope is deliberately narrow: --help/-h are intercepted by clap (they show
rtk's wrapper help) and pytest's short/count version forms are version-
dependent (pytest 9's bare -V runs a session), so only the unambiguous
--version is treated as informational.

Fixes rtk-ai#2096
@maxmilian maxmilian force-pushed the fix/pytest-version-flag-passthrough branch from 698128f to 081c87b Compare May 28, 2026 15:23
@maxmilian maxmilian marked this pull request as ready for review May 28, 2026 15:24
@maxmilian
Copy link
Copy Markdown
Author

Note for the PR Testing Checklist: the "token savings ≥60%" item is N/A here. This is a correctness fix, not a new/compressing filter — rtk pytest --version was being collapsed to "No tests collected" because the filter has no test-session summary to parse. The fix bypasses the filter for --version so pytest's real output reaches the caller. This applies design principle Correctness vs Token Savings: a flag explicitly requesting informational output must not be reformatted into a lossy summary.

Remaining checklist items:

  • Unit tests added (test_version_banner_swallowed_by_filter, test_is_informational_flag, combined-args detection)
  • cargo fmt --all --check && cargo clippy --all-targets && cargo test — all green (1948 passed)
  • Manual rtk pytest --version → real version string; rtk pytest -V confirmed to stay on the filtered path (no regression)

Scope is deliberately narrow (--version only) for correctness — -V/-VV are pytest-version-dependent and --help/-h are handled by clap before reaching the wrapper; details in the PR body.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk pytest --version returns 'no tests collected' — wrapper consumes the flag

1 participant