循环运行全部单元测试

2024-10-01 09:29:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望能够连续运行整个单元测试套件5次。这包括启动、测试以及拆卸方法。在

我尝试过各种方法,包括将整个类添加到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()

Tags: 方法importselfrefortime套件main
2条回答

如果您真的想在一个循环中运行测试,并且您使用的是python2.7+:

# ... skipped ...

if __name__ == "__main__":
    for i in range(5):
        unittest.main(exit=False)

如果您想用基于unittest的测试进行压力测试,请看一下FunkLoad,它正是为此而设计的。在

否则,您将需要修改的测试运行程序。您可以在标准库unittest模块中找到当前测试运行器的代码。很可能您可以实例化一个现有的,然后运行它五次,就像@reclosedev的答案一样。在

相关问题 更多 >