unittest colored output

Solution 1:

Using a method very similar to robert's answer, I have (today!) released a package that enables colour output in unittest test results. I have called it colour-runner.

To install it, run:

pip install colour-runner

Then, where you were using unittest.TextTestRunner, use colour_runner.runner.ColourTextTestRunner instead.

See how it looks with verbosity=1...and verbosity=2

Solution 2:

I'm having good success with nosetests and rednose. It's still maintained at the time of writing this.

Solution 3:

In python 2.x you could try pyrg. Does not work in Python 3 though.

Solution 4:

Make a class that inherits from unittest.TestResult (say, MyResults) and implements a bunch of methods. Then make a class that inherits from unittest.TextTestRunner (say, MyRunner) and override _makeResult() to return an instance of MyResults.

Then, construct a test suite (which you've probably already got working), and call MyRunner().run(suite).

You can put whatever behavior you like, including colors, into MyResults.

Solution 5:

pytest can do this with no changes needed for unit tests.

enter image description here

Now install pytest.

pip install --user pytest

And run the tests to see the color!

enter image description here