pytest-dev / pytest-dev/pytest

Implement a `rich`-based `TerminalReporter`

Open
#14,761 2 comments 3 reactions 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

At the pytest sprint, we discussed making pytest's output more modern (and digestable), drawing inspirations from projects such as:

However, at least for a first step, we want to keep the output similar "in spirit" to what it is now, perhaps with minor improvements like using unicode (if available) to draw lines instead of the current ASCII-based lines.

To do so, we want to drop our custom terminal formatting code in the long run and switch to rich. However, such a switch might be problematic, especially given that rich also uses pytest (and if they break something, they might be unable to run their testsuite). Then again, we depend on pygments and colorama and that has never been much of a problem.

To ease into this, we discussed about the following approach:

  • Have rich as an optional dependency (sadly we don't have default extras quite yet), and have a second internal terminalreporter plugin that takes over (and uses rich for output) if it is installed. It should replicate the current output to a high degree, but based on rich.
  • At some point, make the new rich terminal reporter the default, and add rich as a hard dependency for pytest
  • Perhaps add a fallback mode if something goes wrong with rich, where pytest shows barebones output and a warning (no lines etc., but still enough to use it if absolutely required)
  • Decide what to do with the low-level TerminalWriter. We might still want to keep it as a thin shim around rich. It seems to be private API, however (pytest_terminal_summary gets terminalreporter, and TerminalReporter has a private _tw object).

cc @willmcgugan as a heads-up

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 by reviewing the existing TerminalReporter and the private TerminalWriter (_tw), along with the pytest_terminal_summary entry point. Define how an optional rich-based reporter should preserve current output and how it should interact with rich's optional installation; done requires a working reporter that closely replicates existing output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.