pytest-sugar
pytest-sugar is a plugin for the pytest testing framework that enhances its default output with a cleaner, more readable progress bar and immediate feedback on failing tests. It is actively maintained, currently at version 1.1.1, and releases new versions to support new pytest features or address compatibility issues.
Warnings
- breaking Python 3.7 support was dropped in pytest-sugar v1.0.0. Ensure your environment uses Python 3.8 or newer.
- gotcha pytest-sugar's compatibility with pytest versions is crucial. Version 1.0.0 added explicit support for pytest 8.x. Always ensure your pytest-sugar version is compatible with your installed pytest version to avoid unexpected behavior.
- gotcha Conflicts with other pytest plugins (especially those modifying terminal output) are possible. While v1.1.1 included adjustments to prevent some conflicts, issues can still arise.
Install
-
pip install pytest-sugar
Quickstart
# 1. Install pytest and pytest-sugar
# pip install pytest pytest-sugar
# 2. Create a test file (e.g., test_example.py)
# Then run pytest from your terminal in the same directory.
# --- test_example.py ---
import time
import pytest
def test_passing_example():
assert True
def test_failing_example():
assert False
@pytest.mark.parametrize("i", range(3))
def test_parametrized_example(i):
time.sleep(0.1) # Simulate some work
assert i < 2 # One will fail
def test_long_running_example():
time.sleep(0.5)
assert True
# 3. Run tests using pytest (pytest-sugar is automatically enabled):
# pytest