pytest-pretty
pytest-pretty is an opinionated pytest plugin designed to enhance the readability of test output and simplify the process of identifying and resolving errors. It provides features such as a real-time error summary, a rich, tabulated display of failures, and a more visually appealing overall summary of the test run. The current version is 1.3.0, and while its release cadence is irregular, the project is actively maintained.
Warnings
- gotcha When running pytest-pretty in CI/CD environments such as GitHub Actions, the default terminal width might truncate the rich output. This can make the enhanced summary tables and error details less readable.
- gotcha If you intend to use the `pytester_pretty` fixture (which replaces pytest's built-in `pytester` for interacting with `pytest-pretty`'s modified output), you must explicitly enable the `pytester` plugin.
- breaking As a pytest plugin, `pytest-pretty`'s compatibility and behavior can be indirectly affected by breaking changes in the core `pytest` framework, particularly with major `pytest` version upgrades.
Install
-
pip install -U pytest-pretty
Imports
- pytest-pretty (plugin)
No explicit import usually needed, automatically activated by pytest.
- pytester_pretty (fixture)
from pytest_pretty import pytester_pretty
Quickstart
# test_example.py
def test_passing_example():
assert 1 + 1 == 2
def test_failing_example():
# This assertion will fail to demonstrate the pretty failure output
assert {"a": 1, "b": 2} == {"a": 1, "b": 3}
# To run the tests, navigate to the directory containing test_example.py
# and run the following command in your terminal:
# pytest
# For GitHub Actions, consider adding:
# env:
# COLUMNS: 120
# to your workflow .yml file for better output formatting.