pytest-dev / pytest-dev/pytest
Add --collect-only-tree flag for modern tree-style output
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
--coreflectspytest_collection_modifyitemsreordering.--co-treeanswers "how are tests organized?" which felt more appropriate for a tree visualization. - Verbosity:
-qshows just summary counts,-vincludes 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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