unitest中setup()和teardown()方法只执行一次的模板

import unittest

class Test(unittest.TestCase):

    #整个Test类的开始和结束执行
    @classmethod
    def setUpClass(cls):
        print("test class start =======>")

    @classmethod
    def tearDownClass(cls):
        print("test class end =======>")

    #每个用例的开始和结束执行
    def setUp(self):
        print("test case start -->")

    def tearDown(self):
        print("test case end -->")

    def test_case(self):
        print("test case1")

    def test_case2(self):
        print("test case2")

if __name__ == '__main__':
    unittest.main()

你可能感兴趣的:(测试)