Registry / testing / pytest-rich

pytest-rich

JSON →
library0.2.0pypypiunverified

pytest-rich is a pytest plugin that integrates the rich library to provide enhanced, colorful, and highly readable output for test sessions. It improves the default pytest terminal output with features like better traceback formatting, progress bars, and syntax highlighting. As of version 0.2.0, it is actively maintained with a relatively stable release cadence, primarily focusing on bug fixes and compatibility updates.

pip install pytest-rich
INSTALL
IMPORT
SIG · PYTEST-RICH
P
pytest-rich
testingpythonv0.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

This quickstart demonstrates basic usage of `pytest-rich` by creating a few simple tests (success, failure, error, skipped, warning) and configuring `pytest` via `pyproject.toml` to enable rich output, tracebacks, and help messages. Run `pytest` in the terminal to see the enhanced output.

import pytest import os # Create a dummy test file with open("test_example.py", "w") as f: f.write( """import pytest def test_success(): assert True def test_failure(): assert False def test_error_division_by_zero(): 1 / 0 @pytest.mark.skip(reason="demonstrate skip") def test_skipped(): pass def test_warning(): pytest.warn("This is a test warning.") """ ) # Create a pyproject.toml to enable rich output with open("pyproject.toml", "w") as f: f.write( """[tool.pytest.ini_options] addopts = [ "--rich", "--rich-tracebacks", "--rich-help", "--strict-markers", ] """ ) print("Created test_example.py and pyproject.toml") print("To run, navigate to this directory in your terminal and execute: pytest")
pytest --version
Debug
Known issues
gotchapytest-rich extensively modifies `sys.stdout` and `sys.stderr`. If other pytest plugins or custom test code also heavily manipulate terminal output, conflicts can occur, leading to malformed or incomplete rich output.
fix
If experiencing garbled output, try disabling other output-modifying plugins (e.g., `pytest-xdist`, `pytest-html`) one by one, or run `pytest --disable-rich` to confirm `pytest-rich` is the cause. Review plugin documentation for compatibility notes.
affects: All versions
gotchaWhile `pytest-rich` specifies a minimum `rich` version, using significantly older or very bleeding-edge `rich` versions not fully tested with `pytest-rich` might lead to unexpected rendering issues or visual glitches.
fix
Ensure both `pytest-rich` and `rich` are updated to recent, compatible versions (`pip install --upgrade pytest-rich rich`). Check the `pytest-rich` GitHub repository for known compatibility issues with specific `rich` versions.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'rich' (or 'pytest_rich')
`rich` or `pytest-rich` is not installed in the Python environment currently being used by `pytest`.
fix
Install both libraries: `pip install pytest-rich rich`.
Error: unknown option: --rich
`pytest-rich` is not being loaded by `pytest`. This usually happens if `pytest` is running from a different virtual environment than where `pytest-rich` was installed, or the plugin isn't properly discovered.
fix
Ensure `pytest-rich` is installed in the active virtual environment. Try running `python -m pytest` instead of just `pytest` to ensure you're using the `pytest` executable associated with your current Python environment.
Visual glitches or unformatted output when --rich is enabled
This can be caused by terminal emulator incompatibilities, conflicting `pytest` plugins, or an outdated `rich` library version.
fix
Update `rich` (`pip install --upgrade rich`), try a different terminal emulator, or temporarily disable other `pytest` plugins (`pytest -p no:xdist --rich`) to identify conflicts. Check the `pytest-rich` documentation for known terminal or plugin incompatibilities.
Upgrade
Version history
0.2.0latest on PyPI · released Dec 12, 2024
Audit
Dependencies
pytestrequiredPeer dependency; pytest-rich is a plugin for pytest.
richrequiredCore dependency for rich terminal output.
Agent activity
4 hits · last 30 days
node
4
Resources
pytest-rich — pip install pytest-rich · libregistry