DEV Community

Ajit Kumar
Ajit Kumar

Posted on

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

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
Enter fullscreen mode Exit fullscreen mode

It works—but:

  • No color variation
  • Failures disappear in a sea of .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)

Here are the most impactful pytest plugins for improving output:

Plugin Purpose
pytest-sugar Prettier progress bar, colorful output
pytest-rich Rich-powered console formatting
pytest-clarity Improves assertion diffs
pytest-cov Coverage report with colors and percentages
pytest-instafail Show failures immediately as they happen
pytest-md Markdown output for CI
pytest-tldr Very short summary mode
rich Adds 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
Enter fullscreen mode Exit fullscreen mode

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
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Enter fullscreen mode Exit fullscreen mode

This adds:

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

Enable automatically:

pytest.ini

[pytest]
addopts = -s --disable-warnings
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Run:

pytest --rich
Enter fullscreen mode Exit fullscreen mode

Before Rich

FAILED tests/test_api.py::test_get_user - AssertionError: 404 != 200
Enter fullscreen mode Exit fullscreen mode

After Rich

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

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

────────────────────────────────────────────────────────────────────────────────────────────────────
Enter fullscreen mode Exit fullscreen mode

Rich adds:

  • Colored panels
  • Better tracebacks
  • Better diffs
  • Looks great in CI (GitHub Actions)

5. Pytest Clarity — Better Assertion Diff

Install:

pip install pytest-clarity
Enter fullscreen mode Exit fullscreen mode

Run normally:

pytest
Enter fullscreen mode Exit fullscreen mode

Example Failure (default)

E       AssertionError: assert {'a': 1, 'b': 2} == {'a': 1, 'b': 3}
Enter fullscreen mode Exit fullscreen mode

Example with Clarity enabled

Comparing dicts:
  b:
    - 2
    + 3
Enter fullscreen mode Exit fullscreen mode

Much more readable!


6. Pytest Coverage — Highlight untested code

Install:

pip install pytest-cov
Enter fullscreen mode Exit fullscreen mode

Run with coverage:

pytest --cov=myapp --cov-report=term-missing
Enter fullscreen mode Exit fullscreen mode

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%
Enter fullscreen mode Exit fullscreen mode

You get:

  • Color-coded coverage
  • List of missing lines
  • Summary percent

Works beautifully with Django.


7. Pytest Instafail — Show Failures Immediately

Ideal for long test suites.

pip install pytest-instafail
Enter fullscreen mode Exit fullscreen mode

Run:

pytest --instafail
Enter fullscreen mode Exit fullscreen mode

Now failures appear AS SOON AS THEY HAPPEN, not after all tests complete.


8. Pytest Summary Plugins

pytest-tldr

Gives a super-short summary of test results.

pip install pytest-tldr
Enter fullscreen mode Exit fullscreen mode

Add to config:

[pytest]
addopts = --tldr
Enter fullscreen mode Exit fullscreen mode

Output:

✨ 324 passed | 3 failed | 12 skipped
Enter fullscreen mode Exit fullscreen mode

Perfect for CI dashboards.


9. Combining Plugins for the Best Output

Here’s a recommended combination:

pytest-sugar
pytest-rich
pytest-clarity
pytest-cov
pytest-instafail
pytest-tldr
Enter fullscreen mode Exit fullscreen mode

Add to pytest.ini:

[pytest]
addopts = --rich --tldr --cov=myapp --cov-report=term-missing
Enter fullscreen mode Exit fullscreen mode

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.
Enter fullscreen mode Exit fullscreen mode

10. Extra Tools for CI/CD Formatting

pytest-md (Markdown Output for CI)

pip install pytest-md
pytest --md=report.md
Enter fullscreen mode Exit fullscreen mode

CI can attach the HTML/Markdown output.

pytest-html

pip install pytest-html
pytest --html=report.html --self-contained-html
Enter fullscreen mode Exit fullscreen mode

Produces a professional HTML report with:

  • screenshots
  • logs
  • attachments

Great for Selenium, API tests, Django admin UI tests.


11. What Should Beginners Choose?

Level Recommended Plugins
Beginner pytest-sugar, pytest-clarity
Intermediate pytest-rich, pytest-cov
Advanced pytest-html, pytest-md, pytest-instafail

12. Full Example: requirements-dev.txt for a Beautiful Pytest Setup

pytest==9.0.2
pytest-rich
pytest-sugar
pytest-clarity
pytest-cov
pytest-instafail
pytest-tldr
rich
Enter fullscreen mode Exit fullscreen mode

13. Conclusion

Improving pytest output is one of the easiest ways to:

  • Speed up debugging
  • Reduce cognitive load
  • Improve collaboration with teammates
  • Produce better CI logs
  • Make your test suite more enjoyable

Pytest is powerful—but when paired with the right plugins, it becomes truly developer-friendly.

Top comments (0)