Skip to content

rtk pytest shows "No tests collected" for a collection error (exit 2), masking the ImportError/traceback #3032

Closed

Description

@tonhuu96

Summary

rtk pytest renders a pytest collection error (exit code 2) using the
"No tests collected" summary (pytest's exit-code-5 wording), hiding the
traceback and the real cause. A red TDD state — e.g. a test module that fails
to import a not-yet-created symbol — reads as "nothing ran" instead of the
actual ImportError. This also surfaces through the Claude Code hook, which
rewrites python -m pytest ... → rtk pytest ....

The exit code itself is correct (2), so scripts checking $? are safe — but an
agent or human reading the summary is misled about why the run failed.

Environment

  • rtk 0.43.0 (latest release)
  • Windows 11, Python 3.14, git-bash

Repro

A test module with a bad import (collection error, not a test failure):

# tests/test_x.py
from mypkg import DoesNotExistYet   # ImportError at collection
def test_ok():
    assert True
$ rtk pytest tests/test_x.py -q
Pytest: No tests collected
[full output: .../rtk/tee/....._pytest.log]
$ echo $?
2

Raw pytest (via rtk proxy) shows the truth:

$ rtk proxy python -m pytest tests/test_x.py -q
...
E   ImportError: cannot import name 'DoesNotExistYet' from 'mypkg'
=========================== short test summary info ===========================
ERROR tests/test_x.py
!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
1 error in 0.39s

Expected

Distinguish a collection error (exit 2 — errors during collection) from a
genuine no tests collected (exit 5). For the exit-2 case, surface the error
count and at least the first error line / failing module, e.g.:

Pytest: 1 error during collection — tests/test_x.py: ImportError: cannot import name 'DoesNotExistYet'

so the summary points at the real cause instead of the misleading "No tests
collected".

Workaround

exclude_commands = ["python"] under [hooks] in config.toml (rtk reduces
python -m pytest to base command python, so ["pytest"] does not match),
or rtk proxy python -m pytest ... for full output.

Activity

  1. pszymkowiak commented on Jul 17, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 90%

    Summary

    rtk pytest's collection-error (exit 2) path reuses the 'No tests collected' (exit 5) summary, hiding the ImportError/traceback; should detect exit-2 collection errors and surface the error count plus first failing module/line.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.


    Triaged automatically by wshm · This is an automated analysis, not a human review.

  2. vanhumbeecka commented on Jul 17, 2026

    @vanhumbeecka

    Similar issue: Claude models are often confused when "No tests collected" is returned by RTK - they go on a treasure-hunt finding the root cause for this one.
    Fable's own conclusion: summarizing empty output as "No tests collected" is a fabricated conclusion. Silence should stay silent. This is the part that actually costs time, and a memory note won't fix it for anyone else.

  3. KuSh commented on Sep 5, 2026

    @KuSh
    Collaborator

    This is fixed on develop. Running the repro (a test module whose import fails) with rtk pytest tests/test_x.py -q now prints the full collection ERRORS block, including the ImportError traceback and Interrupted: 1 error during collection, and still exits 2 — the misleading 'No tests collected' summary is no longer used for exit-2 collection errors. Closing; please reopen or comment if you still see it on the latest version.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibugpriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions