Python - 当异常未引发时成功的测试 [英] Python - test that succeeds when exception is not raised
本文介绍了Python - 当异常未引发时成功的测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道 unittest
Python模块。
I know about unittest
Python module.
我知道关于 assertRaises()
方法 TestCase
class。
I know about assertRaises()
method of TestCase
class.
我想写一个成功的测试
请提供任何提示?
推荐答案
测试运行器将捕获您不会提出的所有异常。
因此:
The test runner will catch all exceptions you didn't assert would be raised. Thus:
doStuff()
self.assert_(True)
这应该可以正常工作。你可以放弃self.assert_调用,因为它没有做任何事情。我喜欢把它放在那里记录我没有忘记一个断言。
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.
这篇关于Python - 当异常未引发时成功的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文