接上文,执行测试用例中的setup等等:
这里有个上下文管理器with, 关于这个,有个文章写得挺好:python上下文管理器ContextLib及with语句http://blog.csdn.net/pipisorry/article/details/50444736 。
self.setUp()要先执行,执行无异常后,再执行testMethod()和self.tearDown()
try:
self._outcome = outcome
with outcome.testPartExecutor(self):
self.setUp()
if outcome.success:
outcome.expecting_failure = expecting_failure
with outcome.testPartExecutor(self, isTest=True):
testMethod()
outcome.expecting_failure = False