[英]Unit test in Python, error in setup class
我将测试套件编写为:
class MySuite(unnitest.Testcase):
@classmethod
def setUpclass(cls):
try:
***some code which will throw exception***
except Exception as e:
print('Error Thrown')
@classmethod
def tearDownClass(cls):
print('In teardown')
def test_demo(self):
print('In test_demo')
问题是,尽管将在安装过程中抛出错误( 由于5/0 ),但是test_demo将被执行,我不想这样做。
当安装方法中出现错误时,最好的方法是停止执行test_demo。
您正在捕获错误,只是打印一条消息作为响应。 不要那样做
如果您确实要打印某些内容,请至少在以后重新引发异常。 但是最好不要打扰到它:回溯应该是足够的信息。
(此外,类方法的第一个参数通常称为cls
not self
,因为它是类本身。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.