pytest-dev / pytest-dev/pytest

Add --collect-only-tree flag for modern tree-style output

Open
#14,150 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

What's the problem this feature will solve?

The current --collect-only output uses an XML-like <Type name> format that feels a bit... vintage:

<Dir pytest>
  <Dir testing>
    <Module test_example.py>
      <Class TestFoo>
        <Function test_bar>

While this format has served us well, it's 2026 now and we have nicer ways to visualize hierarchical data. The angle-bracket format is difficult to scan visually, especially for large test suites, and doesn't leverage modern terminal capabilities.

Describe the solution you'd like

A new --collect-only-tree (or --co-tree) flag that displays collected tests as a proper tree with box-drawing characters:

pytest
└── testing
    └── test_example.py
        └── TestFoo
            └── test_bar

With support for:

  • Box-drawing characters (├── └── │), ASCII fallback for non-UTF-8
  • Colors: bold for files/dirs, cyan for classes, green for test functions
  • Proper tree structure showing sibling relationships

This provides the same information but in a format that's easier to read at a glance.

Alternative Solutions

The existing --collect-only would remain unchanged for backward compatibility and tooling that may parse its output. The tree format is purely additive as a new flag.

One could write a plugin or post-process the output, but this seems useful enough to warrant inclusion in core pytest.

Additional context

I have a working implementation ready: https://github.com/sclaughl/pytest/tree/feature/collect-only-tree-flag

A few design notes:

  • Structural vs execution order: The tree shows tests grouped by their hierarchy (directory/module/class), not the order they'll run. The classic --co reflects pytest_collection_modifyitems reordering. --co-tree answers "how are tests organized?" which felt more appropriate for a tree visualization.
  • Verbosity: -q shows just summary counts, -v includes docstrings alongside test names
  • Architecture: Separated tree-building from rendering so other output formats (JSON tree, etc.) could reuse the structure if desired

Happy to adjust any of this based on feedback. And yes, I checked -- pytest-collect-formatter exists but outputs JSON/YAML/XML for machines, not a visual tree for humans.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the existing --collect-only entry point and the feature/collect-only-tree-flag implementation linked in the issue. Review how pytest_collection_modifyitems affects ordering, then compare the implementation with the requested tree structure, encoding fallback, colors, verbosity, and backward compatibility. Done means the additive flag provides the described output without changing --collect-only.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.