我希望能够连续5次运行整个单元测试testSuite。这包括启动、测试以及拆卸方法。
我已经尝试了所有的方法,包括将整个类添加到for循环中,但都没有成功。谢谢你的帮助。
import unittest, time, re
class IIIAppforloop(unittest.TestCase):
def setUp(self):
print("setting up")
def testappforloop(self):
print ("testappforloop1")
def testappforloop2(self):
print ("testappforloop2")
def tearDown(self):
print ("tearing down")
if __name__ == "__main__":
unittest.main()发布于 2012-01-28 03:24:41
如果你真的想在循环中运行测试,并且你使用的是Python 2.7+:
# ... skipped ...
if __name__ == "__main__":
for i in range(5):
unittest.main(exit=False)发布于 2012-01-28 03:46:42
如果你想用基于单元测试的测试进行压力测试,看看FunkLoad,它就是为此而设计的。
否则,您将需要一个经过修改的测试运行器。您可以在标准库unittest module中找到当前测试运行器的代码。很可能你可以实例化一个已有的,然后运行五次,就像@reclosedev的答案一样。
https://stackoverflow.com/questions/9038658
复制相似问题