import unittest
def setUpModule():
print("setUpModule >>>")
def tearDownModule():
print("tearDownModule >>>")
class Test1(unittest.TestCase):
@classmethod
def setUpClass(cls):
print("setUpClass for Test1 >>")
@classmethod
def tearDownClass(cls):
print("tearDownClass for Test1 >>")
def setUp(self):
print("setUp for Test1 >")
def tearDown(self):
print("tearDown for Test1 >")
def testCase1(self):
print("testCase1 for Test1")
def testCase2(self):
print("testCase2 for Test1")
class Test2(unittest.TestCase):
@classmethod
def setUpClass(cls):
print("setUpClass for Test2 >>")
@classmethod
def tearDownClass(cls):
print("tearDownClass for Test2 >>")
def setUp(self):
print("setUp for Test2 >")
def tearDown(self):
print("tearDown for Test2 >")
def testCase1(self):
print("testCase1 for Test2")
def testCase2(self):
print("testCase2 for Test2")
if __name__ == "__main__":
unittest.main()
setUpModule >>>
setUpClass for Test1 >>
setUp for Test1 >
testCase1 for Test1
tearDown for Test1 >
setUp for Test1 >
testCase2 for Test1
tearDown for Test1 >
tearDownClass for Test1 >>
setUpClass for Test2 >>
setUp for Test2 >
testCase1 for Test2
tearDown for Test2 >
setUp for Test2 >
testCase2 for Test2
tearDown for Test2 >
tearDownClass for Test2 >>
tearDownModule >>>
本系列文章和代码已经作为项目归档到github,仓库地址:jumper2014/PyCodeComplete。大家觉得有帮助就请在github上star一下,你的支持是我更新的动力。什么?你没有github账号?学习Python怎么可以没有github账号呢,快去注册一个啦!