Python unittest - opposite of assertRaises?

前端 未结 10 689
甜味超标
甜味超标 2020-12-04 05:36

I want to write a test to establish that an Exception is not raised in a given circumstance.

It\'s straightforward to test if an Exception is raise

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 06:00

    One straight forward way to ensure the object is initialized without any error is to test the object's type instance.

    Here is an example :

    p = SomeClass(param1=_param1_value)
    self.assertTrue(isinstance(p, SomeClass))
    

提交回复
热议问题