unittest colored output

前端 未结 9 2080
予麋鹿
予麋鹿 2020-12-13 17:39

I use unittest (actually unittest2) for Python testing, together with Python Mock for mocking objects and nose to run all tests in a single pass.

相关标签:
9条回答
  • 2020-12-13 17:53

    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

    0 讨论(0)
  • 2020-12-13 17:53

    I've also found another colouring plugin for nose: YANC at https://pypi.python.org/pypi/yanc

    Works for me with Python 3.5 and nose 1.3.7 (I couldn't get any of the other options for nose listed above to work)

    0 讨论(0)
  • 2020-12-13 17:58

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

    Now install pytest.

    pip install --user pytest
    

    And run the tests to see the color!

    0 讨论(0)
  • 2020-12-13 18:03

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

    0 讨论(0)
  • 2020-12-13 18:07

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

    0 讨论(0)
  • 2020-12-13 18:10

    Try rudolf plugin for nosetests.

    0 讨论(0)
提交回复
热议问题