unittest colored output

前端 未结 9 2099
予麋鹿
予麋鹿 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 18:16

    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.

提交回复
热议问题