Making Pytest Beautiful: A Complete Guide to Improving Test Output (with Plugins & Examples)

Published: (December 12, 2025 at 03:40 AM EST)
3 min read
Source: Dev.to

Source: Dev.to

Pytest is already one of the best testing frameworks in Python—but its default output is plain, and sometimes difficult to parse when you’re running a large test suite.

If you’ve ever squinted at a wall of plain‑text failures, or wished your test results had more color, structure, or interactivity… you’re in the right place.

In this guide, we’ll explore:

  • Why pytest output looks the way it does
  • How to enhance pytest output using community plugins
  • Side‑by‑side examples of different output styles
  • Plugins for beginners, intermediate users, and advanced setups
  • Command‑line usage, setup instructions, and configuration tips

Whether you’re a Django, FastAPI, data, or backend developer—this guide will dramatically improve your testing experience.

1. Why Pytest Output Is Boring by Default

Default pytest output:

collected 12 items

test_example.py .......F....

================================ FAILURES ================================
_______________________________ test_function ____________________________

AssertionError: assert 2 == 5

Issues

  • No color variation
  • Failures disappear in a sea of . and F
  • Hard to read when running dozens or hundreds of tests
  • CI logs become painful to inspect

So let’s fix that.

2. Making Pytest Beautiful (Essential Plugins)

PluginPurpose
pytest-sugarPrettier progress bar, colorful output
pytest-richRich‑powered console formatting
pytest-clarityImproves assertion diffs
pytest-covCoverage report with colors and percentages
pytest-instafailShow failures immediately as they happen
pytest-mdMarkdown output for CI
pytest-tldrVery short summary mode
richAdds color + formatting engine

Let’s go step‑by‑step.

3. Pytest Sugar — Prettier Test Progress

Best for: beginners, immediate improvement

Install

pip install pytest-sugar

Sample Output

──────────────────────────────────────────────────────────────────────────── pytest session starts ────────────────────────────────────────────────────────────────────────────
platform linux -- Python 3.10, pytest-9.0.2
rootdir: /home/project

 ❱ megaproject/tests/crm/test_example.py ✓ ✓ ✓ ✓  

 4 passed in 0.14s
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Adds:

  • A progress bar
  • Unicode glyphs
  • Colored passes/fails
  • Cleaner failure messages

Enable automatically

pytest.ini

[pytest]
addopts = -s --disable-warnings

pytest-sugar loads automatically when installed.

4. Pytest Rich — Rich Console Output (Beautiful Colors + Layout)

Best for: developers who want maximum readability

Install

pip install pytest-rich

Run

pytest --rich

Before Rich

FAILED tests/test_api.py::test_get_user - AssertionError: 404 != 200

After Rich

────────────────────────────── FAILED tests/test_api.py::test_get_user ──────────────────────────────
❌ AssertionError: Expected HTTP 200, got 404

Path: /api/v1/user/
Payload: {"id": 1}
────────────────────────────────────────────────────────────────────────────────────────────────────

Rich adds:

  • Colored panels
  • Better tracebacks
  • Improved diffs
  • Great appearance in CI (e.g., GitHub Actions)

5. Pytest Clarity — Better Assertion Diff

Install

pip install pytest-clarity

Run normally:

pytest

Example Failure (default)

E       AssertionError: assert {'a': 1, 'b': 2} == {'a': 1, 'b': 3}

Example with Clarity enabled

Comparing dicts:
  b:
    - 2
    + 3

Much more readable!

6. Pytest Coverage — Highlight Untested Code

Install

pip install pytest-cov

Run with coverage

pytest --cov=myapp --cov-report=term-missing

Output

----------- coverage: platform linux, python 3.10 -----------
Name                         Stmts   Miss  Cover   Missing
----------------------------------------------------------
myapp/models.py               120     10    92%    144-152
myapp/views.py                 80     25    69%    35-60
----------------------------------------------------------
TOTAL                         200     35    83%

Features:

  • Color‑coded coverage
  • List of missing lines
  • Summary percentage

Works beautifully with Django.

7. Pytest Instafail — Show Failures Immediately

Ideal for long test suites.

Install

pip install pytest-instafail

Run

pytest --instafail

Now failures appear as soon as they happen, not after all tests complete.

8. Pytest Summary Plugins

pytest‑tldr

Provides a super‑short summary of test results.

Install

pip install pytest-tldr

Add to config

pytest.ini

[pytest]
addopts = --tldr

Output

✨ 324 passed | 3 failed | 12 skipped

Perfect for CI dashboards.

9. Combining Plugins for the Best Output

Recommended combination

pytest-sugar
pytest-rich
pytest-clarity
pytest-cov
pytest-instafail
pytest-tldr

Add to pytest.ini

[pytest]
addopts = --rich --tldr --cov=myapp --cov-report=term-missing

Sample final output

🔥 Running tests with style…

───────────────────────── 12 passed, 1 failed, 2 skipped in 2.31s ─────────────────────────
----------- coverage: platform linux, python 3.10 -----------
Name                         Stmts   Miss  Cover   Missing
-----------------------------------------------------------
myapp/models.py               120     10    92%    144-152
-----------------------------------------------------------
✨ Done! 92% coverage.

10. Extra Tools for CI/CD Formatting

pytest‑md (Markdown Output for CI)

pip install pytest-md
pytest --md=report.md

The generated Markdown can be attached to CI reports.

pytest‑html

pip install pytest-html
pytest --html=report.html --self-contained-html

Creates a self‑contained HTML report suitable for sharing with stakeholders.

Back to Blog

Related posts

Read more »