Outputting data from unit test in Python

前端 未结 14 2493
孤城傲影
孤城傲影 2020-12-02 05:45

If I\'m writing unit tests in python (using the unittest module), is it possible to output data from a failed test, so I can examine it to help deduce what caused the error?

14条回答
  •  感动是毒
    2020-12-02 06:25

    Expanding @F.C. 's answer, this works quite well for me:

    class MyTest(unittest.TestCase):
        def messenger(self, message):
            try:
                self.assertEqual(1, 2, msg=message)
            except AssertionError as e:      
                print "\nMESSENGER OUTPUT: %s" % str(e),
    

提交回复
热议问题