How to show the error messages caught by assertRaises() in unittest in Python2.7?

前端 未结 5 1312
长情又很酷
长情又很酷 2020-12-07 18:27

In order to make sure that the error messages from my module are informative, I would like to see all the error messages caught by assertRaises(). Today I do it for each ass

5条回答
  •  时光说笑
    2020-12-07 18:56

    If you want the error message exactly match something:

    with self.assertRaises(ValueError) as error:
      do_something()
    self.assertEqual(error.exception.message, 'error message')
    

提交回复
热议问题