Pytest-sugar is really tasty

John Byrne
2 min readApr 16, 2020

I am pretty new to Python but the team I worked in drilled into me the value of TDD or at the very least good tests around your code. As I was scrolling through twitter one evening I came across a little test library called pytest-sugar.

So what is pytest-sugar I hear you say? Well according to the docs it simply changes the default look and feel of pytest, adds a progress bar, and shows failing tests instantly.

Here I have the output of passing tests without pytest-sugar.

Passing tests

And now with pytest-sugar.

Still passing tests

As you can see both are essentially the same output but I honestly find the graphic progress bar, the ticks per test file and the summary really nice to read and understand.

So no real value at the minute? Well let us see what happens when we have failing tests, first without pytest-sugar.

Failing Tests

And now with pytest-sugar!

Still failing tests

Well as you can see with the obvious difference of the red crosses versus a F there is still the relevant stack trace but if you look at the bottom you will see the summary is now very different and this is where the value of pytest-sugar comes to the front.

In this very simple example there is a single failing test file yet it shows a nicely ordered list to allow you to navigate all the failing tests you may have rather than going through the output to identify them.

Summary

For little or no overheard you get a more visual and organised output from your tests that allow you to navigate them much easier.

It offers a nice graph at the side so you can see where the majority of your tests are and aren’t. This provides you with nice visual feedback while developing without needing to go all the way through generating a coverage report. Note that while it is a nice visual feedback it is not a coverage tool.

--

--