Add --collect-only-tree flag for tree-style collection output#14151
Add --collect-only-tree flag for tree-style collection output#14151sclaughl wants to merge 4 commits intopytest-dev:mainfrom
Conversation
Because it's no longer 2005 and we don't have to pretend we're writing XML. The new --co-tree flag displays collected tests as a tree with box-drawing characters (├── └── │) instead of the classic <Type name> format. Features: - Box-drawing characters for TTY, ASCII fallback for non-TTY - Colors: bold for files/dirs, cyan for classes, green for functions - Custom collector types shown with (TypeName) annotation - Proper deduplication for overlapping collection paths Architecture: - New CollectionTree class separates tree-building from rendering - Classic --collect-only unchanged (preserves execution order view) - Tree view shows structural hierarchy (groups by module/class) Design note: --co-tree deliberately shows structural organization rather than execution order. It does not reflect pytest_collection_modifyitems reordering. Use --co for execution order, --co-tree for structure.
- Remove unused render_classic method - Fix Unicode detection: check file encoding instead of color support - Update docs to clarify structural vs execution order difference - Add tests for parametrized tests and --co/--co-tree precedence - Update test patterns to use Unicode box-drawing characters
|
Thanks @sclaughl for the PR. It seems very complete and well written. However, I'm personally hesitant to add yet another flag (and a bunch of code to maintain) regarding this feature. In my opinion we have 2 options:
What other maintainers think? |
|
Its tricky the tree display is not meant for parsing so replacing is acceptable The key details of reorder vs compact need some bikeshedding |
|
I'd be happy to replace To be explicit about the design: the tree shows structural organization (by directory/module/class) and would not reflect reordering from For anyone who needs execution order, This seems like a good trade-off -- a proper tree can't represent arbitrary reordering without breaking its structure. Just wanted to flag it clearly since it's a behavior change. Happy to rework the PR if you'd like to go in that direction. |
Closes #14150
Adds a new
--collect-only-tree(--co-tree) flag that displays collected tests as a tree with box-drawing characters,providing a more readable alternative to the classic
<Type name>format.Features:
-q(summary only) and-v(shows docstrings)The existing
--collect-onlybehavior is unchanged.