Skip to content

fix(pytest): handle --collect-only output correctly - #925

Closed
tangi-vass wants to merge 1 commit into
rtk-ai:developfrom
tangi-vass:fix/pytest-collect-only
Closed

tangi-vass wants to merge 1 commit into
rtk-ai:developfrom
tangi-vass:fix/pytest-collect-only

Conversation

@tangi-vass

Copy link
Copy Markdown

Summary

  • RTK's pytest filter misclassified --collect-only output as "No tests collected" because the summary line says "N tests collected" not "N passed/failed"
  • Detect --collect-only/--co flag: skip injecting -q/--tb=short, route to dedicated filter_collect_only_output() that preserves the test tree
  • Fix misleading debug eprintln that hardcoded injected flags

Context

Agents using RTK spent ~7 extra turns investigating phantom "test discovery is broken" before bypassing RTK with rtk proxy.

Test plan

  • test_filter_collect_only — verifies tree preserved and count correct
  • test_filter_collect_only_zero_items — edge case with 0 items
  • All 11 pytest tests pass, 1130 total tests pass
  • cargo fmt && cargo clippy --all-targets clean

🤖 Generated with Claude Code

@CLAassistant

CLAassistant commented Mar 30, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@tangi-vass
tangi-vass changed the base branch from master to develop March 30, 2026 12:37
pytest --collect-only produces a test tree with "N tests collected"
summary, not "N passed/failed". The existing filter misclassified
this as "No tests collected", causing agents to waste turns
investigating phantom test discovery failures.

- Detect --collect-only/--co and skip injecting -q/--tb=short
- Route to dedicated filter that preserves the test tree
- Fix misleading debug eprintln that hardcoded injected flags

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@tangi-vass
tangi-vass force-pushed the fix/pytest-collect-only branch from dc9c20a to 1d2762b Compare March 30, 2026 12:55
liza-mas pushed a commit to liza-mas/liza that referenced this pull request Apr 17, 2026
Use rtk proxy when running pytest --collect-only while waiting for the fix.
See rtk-ai/rtk#925
@mattbuot

Copy link
Copy Markdown

Confirming this is still live on develop five months on, in case it reads as stale.

src/cmds/python/pytest_cmd.rs on develop still has no --collect-only / --co branch and still injects --tb=short and -q unconditionally (lines 35 and 38). Reproduced on rtk 0.45.0, macOS arm64, Homebrew:

$ uv run rtk proxy pytest --collect-only -q | tail -1
3971/4018 tests collected (47 deselected) in 9.77s

$ uv run rtk pytest --collect-only -q
Pytest: No tests collected

One thing worth folding in if this gets picked up: the real summary line carries a collected / total pair and a (N deselected) clause, so matching on a bare N tests collected will miss projects that deselect.

This is also the actual root cause behind #3565, which was filed against the uv run rewrite path instead — I have commented there pointing here.

The PR is mergeable_state: dirty and not rebaseable in place. @tangi-vass, are you still on this? If not I can rebase it onto current develop with your commit preserved.

@KuSh

KuSh commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this. Closing it in favour of #4192, which fixes the same --collect-only result on the current pytest runner: it reads pytest's N tests collected summary, so it also handles --co -q (counted as 0 tests on this branch), -k deselection, and keeps the raw output when collection hits an error. If you think the collected test list should be shown and not only the count, please say so on #4192, or reply here if your scope differs.

@KuSh KuSh closed this Oct 23, 2026
@KuSh KuSh added the duplicate This issue or pull request already exists label Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants