Python unittest - opposite of assertRaises?

前端 未结 10 666
甜味超标
甜味超标 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:07

    Just call the function. If it raises an exception, the unit test framework will flag this as an error. You might like to add a comment, e.g.:

    sValidPath=AlwaysSuppliesAValidPath()
    # Check PathIsNotAValidOne not thrown
    MyObject(sValidPath)
    

提交回复
热议问题