执行测试用例套件
....
TextTestRunner.run(suite)
....
TextTestRunner.run(suite)针对每个测试用例类中每个以test开头的测试用例,都会去调用case.py中run() 方法。
详情分析见:源码分析-测试用例是如何执行的?
2 . case.py文件中run()方法中有定义在每次执行以test开头的测试用例之前,会先调用setUp(),测试用例执行完成,调用tearDown()
源码:
try:
success = False
try:
self.setUp() # 这就是setUp()
except SkipTest as e:
self._addSkip(result, str(e))
except KeyboardInterrupt:
raise
except:
result.addError(self, sys.exc_info())
else:
try:
testMethod() #执行测试用例,以test开头的
except KeyboardInterrupt:
....
....
....
try:
self.tearDown() #这就是tearDwon()
except KeyboardInterrupt: