Python - test that succeeds when exception is not raised

前端 未结 3 1489
时光取名叫无心
时光取名叫无心 2021-02-19 04:20

I know about unittest Python module.

I know about assertRaises() method of TestCase class.

I would like to write a test th

3条回答
  •  清歌不尽
    2021-02-19 04:37

    The test runner will catch all exceptions you didn't assert would be raised. Thus:

    doStuff()
    self.assert_(True)
    

    This should work fine. You can leave out the self.assert_ call, since it doesn't really do anything. I like to put it there to document that I didn't forget an assertion.

提交回复
热议问题