Skip to content

fix: pass --version/--help through pytest wrapper unfiltered - #4094

Open
Cornul11 wants to merge 4 commits into
rtk-ai:developfrom
Cornul11:fix/pytest-passthrough-flags
Open

Cornul11 wants to merge 4 commits into
rtk-ai:developfrom
Cornul11:fix/pytest-passthrough-flags

Conversation

@Cornul11

@Cornul11 Cornul11 commented Sep 17, 2026 •

Copy link
Copy Markdown

Summary

  • rtk pytest --version (and --help/-h) was run through the pass/fail parser like a normal test run. That output has no "N passed/failed" summary line, so the parser's zero-counts fallback fired and reported Pytest: No tests collected instead of the actual version/help text. Follows the passthrough pattern the JVM (mvn --version) and PHP (pint/phpstan) wrappers already use: detect the utility flag, skip injecting --tb=short -q -rxX, emit raw output instead of running it through filter_pytest_output.

    Fixes rtk pytest --version returns 'no tests collected' — wrapper consumes the flag #2096.

  • A pytest collection/fixture error (=== ERRORS === section, "1 error in Xs" summary with no passed/failed/skipped word) hit the same zero-counts fallback and was also misreported as No tests collected. Fixed by treating === ERRORS === like === FAILURES ===, recognizing error/errors in both summary-line forms, tracking an errors count, and rendering ERROR <path> - <reason> lines like FAILED lines.

  • A verbosity level that prints no summary line at all — e.g. rtk's injected -q stacking with a project's addopts = -q into -qq — also hit the zero-counts fallback, at exit 0, despite tests having actually run and passed. pytest's own exit codes guarantee 0 only when at least one test was collected and passed, so No tests collected can never be legitimate there. The existing raw-output fallback (added in 86b34df) only covered exit_code != 0; extended the guard to trigger on any exit code except pytest's own "no tests collected" exit (5), so this case now falls back to raw output instead of asserting the impossible.

Related work / overlap — please dedupe rather than review 4x

This repo already has several open, unmerged PRs touching this exact "pytest/tool-filter reports a false green" bug class in pytest_cmd.rs — and, to be clear having now checked history, this repo does merge scoped fixes here regularly (86b34df, aba7643, ecc34d7 all landed on this file). This is a backlog/dedup problem, not a "nothing gets reviewed" problem:

Related: #2096, #2317, #2960, #3565, #3588, #1417

Test plan

  • cargo test pytest_cmd — 14/14 pass, including new tests for --version passthrough, a pure collection error, a mixed passed/failed/error run, the double--q-at-exit-0 fallback, and the genuine no-tests-collected-at-exit-5 case
  • cargo fmt
  • cargo test — full suite, 0 failures

Update (after review)

Rebased onto current develop, and fixed the two help-passthrough problems from the review:

  • rtk pytest --help and -h never reached the wrapper, because clap answered them first. Pytest now has #[command(disable_help_flag = true)], as Psql and Ctest do. If fix(cli): hand -h, --help and help to the tool each subcommand wraps #4348 lands first, the attribute goes away in a rebase.
  • Help and version output is now returned unchanged. Before, fallback_tail kept only the last 60 lines and printed "output format not recognized".

The rebase brought in three upstream changes to pytest_cmd.rs: ANSI stripping inside the parser (#4465), the test duration on the summary line, and display_args. The new errors count now sits beside duration. The Commands enum moved from main.rs to lib.rs.

Test plan, on 02a0066b:

  • test_pytest_help_passthrough_args parses --help, -h and --version through clap, not just the helper
  • Against real pytest 9.1.1: rtk pytest --help, -h, -- --help and -- -h print the same 365 lines as native pytest --help, with exit 0 and nothing on stderr. --version matches too.
  • cargo fmt --all, cargo fmt --manifest-path proxy/Cargo.toml --all --check, cargo clippy --all-targets -D warnings
  • cargo test --all: 4,885 passed, 0 failed

@CLAassistant

CLAassistant commented Sep 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working cli python labels Sep 17, 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 wrapper so that utility flags like --version, --help, and -h bypass the default test-runner argument injection and pass/fail output parsing, instead emitting raw output via a tail fallback. This follows the same passthrough pattern already used by the JVM and PHP command wrappers.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #2096


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.

Tested exact head f09fdc3a523330652ad4410fe8f910ba7a906ab8 against its base 5e0f92cd108fc5a985022c5eb525a401f97fa11f with real pytest 9.0.3 on Linux: 17 scenarios / 51 raw-base-head executions, identical exit codes; 14 focused pytest tests, fmt and warnings-denied clippy pass.

Requesting changes for the advertised help passthrough:

  1. rtk pytest --help and rtk pytest -h still print the 11-line RTK subcommand help, not pytest's help. Clap handles them before is_passthrough_flag runs. The helper-only unit test misses this public CLI behavior. #4348 already addresses this overlapping CLI/runner problem; please coordinate with that work.
  2. Using rtk pytest -- --help (or -- -h) reaches the new helper, but fallback_tail(..., 60) returns only the last 60 of pytest's 356 help lines. The usage, positional arguments and options such as --maxfail disappear. It also reports “output format not recognized” for an intentionally recognized utility command.

Please make the actual CLI forward pytest's help and preserve its useful help content rather than taking only its tail. Add CLI-level checks for ordinary and separator-forwarded help, comparing the usage/options with native pytest.

The repeated version query, mixed passed/fixture-error count and ordinary double-quiet successful run behave correctly on this head. A separate, inherited limitation remains in the third commit's no-summary handling: with addopts = -q, a failing test that prints 99 passed in 0.01s still renders only Pytest: 99 passed and loses the failure details (exit 1 is preserved). This is the same residual #2960 case documented in the #2963 review, not a new regression introduced here; coordinate trusted-summary parsing with #3355 when choosing the overlapping fixes.

No full-suite, historical-pytest, external-plugin or cross-platform validation in this review.

@Cornul11
Cornul11 force-pushed the fix/pytest-passthrough-flags branch from f09fdc3 to 02a0066 Compare October 14, 2026 13:35
@Cornul11

Copy link
Copy Markdown
Author

@Protocol-zero-0 Rebased onto current develop and fixed both:

  1. Pytest now has disable_help_flag = true, as Psql/Ctest do, so -h/--help reach pytest. test_pytest_help_passthrough_args parses them through clap. Checked against pytest 9.1.1: rtk pytest --help, -h, -- --help and -- -h print the same 365 lines as native pytest --help, with exit 0 and nothing on stderr. If fix(cli): hand -h, --help and help to the tool each subcommand wraps #4348 lands first, the attribute goes away in a rebase.
  2. Help and version output passes through unchanged: no tail and no "format not recognized" warning.

I've left item 3 out, since it's the inherited #2960 case.

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

The two help-passthrough blockers from my earlier review are resolved on exact head 02a0066bdfc87c739d2f2ce0e75328b4f2f7a72d.

Independently checked real pytest 9.0.3 on Linux against current base f53e60337eacf9f300801c4622dc711bd56d8abb: 17 scenarios, 51 raw/base/head executions plus 14 direct-executable utility checks. Ordinary --help/-h and separator-forwarded forms now preserve all 356 help lines, including usage and --maxfail; their stdout and stderr are byte-identical to the native pytest executable with color disabled. Version, repeated version and separator-forwarded version match too. Exit codes remain aligned with native pytest across passing, failing, fixture/collection-error and empty-suite cases. Double-quiet passing tests no longer claim that no tests were collected.

18 focused parser tests, the CLI-level help argument test, fmt and warnings-denied clippy pass. No full-suite, historical-pytest, external-plugin or cross-platform validation in this review.

The inherited #2960 case where captured 99 passed masks failure details still reproduces with exit 1 preserved; this revision does not introduce it. Keep coordinating trusted-summary parsing with #3355 and the broader help work with #4348 when integrating the overlapping fixes.

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

Labels

bug Something isn't working cli python

Projects

None yet

3 participants