Skip to content

pytest filter reports "No tests collected" for runs that executed tests; a colored '1 failed' vanishes from the summary #2960

Description

@xuing

What happens

Two distinct, unreported triggers make rtk pytest report Pytest: No tests collected (and silently discard the collected FAILURES section) for runs that actually executed tests — including failing ones. Both reproduced on rtk 0.43.0 and present in develop (5d32d07: the -q injection in pytest_cmd.rs::run and the zero-count early return in build_pytest_summary).

For an agent that reads the filtered text, this is a false green: a failing test run comes back looking like an empty one.

Trigger 1 — the injected -q doubles up with the project's addopts = -q

rtk pytest unconditionally appends -q when the CLI args don't contain it. It cannot see the project's pytest config; with this textbook pytest.ini:

[pytest]
addopts = -q

every run is effectively -qq — a verbosity level at which pytest prints no final summary line at all. No summary line → all counts parse to zero → "No tests collected", and the early return drops the FAILURES that the state machine had already collected.

$ rtk pytest tests/test_contracts.py        # 20 passing tests, addopts = -q
Pytest: No tests collected
$ echo $?
0

Same command through rtk proxy: 20 passed, 1 warning in 0.04s.

With a file containing 2 real failing tests, the filtered run still prints Pytest: No tests collected and exits 0.

Trigger 2 — ANSI-colored summaries defeat the count parser

parse_summary_line does words[i-1].parse::<usize>() on raw text. Under FORCE_COLOR / PY_COLORS / CI, pytest wraps the counts in escapes, and \x1b[32m30 is not a number:

$ printf '\x1b[32m30 passed\x1b[0m\x1b[33m, 1 warning\x1b[0m\x1b[32m in 0.11s\x1b[0m'  # fixture
→ Pytest: No tests collected

Worse, on a mixed line the failure count alone is dropped (its 1 carries the color prefix; passed's survives after the comma split):

$ printf '\x1b[31m1 failed\x1b[0m\x1b[32m, 1 passed\x1b[0m\x1b[31m in 0.05s\x1b[0m'  # fixture
→ Pytest: 1 passed          # the failure is gone from the summary

Relationship to existing work

PR incoming with a fix + regression tests for both triggers.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions