class TestCase:
def run(self, result=None):
if result is None:
result=self.defaultTestResult()
result.startTest(self)
testMethod = getattr(self, self._testMethodName)
try:
try:
self.setUp()
except KeyboardInterrupt:
raise
except:
result.addError(self, self._exc_info())
return
ok = False
n = 1
try:
while n<=self.repeat or ok is False:
try:
testMethod()
ok = True
break
except Exception as e:
if n == self.repeat:
raise self.failureException(str(e))
finally:
n+=1
except self.failureException:
result.addFailure(self, self._exc_info())
except KeyboardInterrupt:
raise
except:
result.addError(self, self._exc_info())
try:
self.tearDown()
except KeyboardInterrupt:
raise
except:
result.addError(self, self._exc_info())
ok = False
if ok: result.addSuccess(self)
finally:
result.stopTest(self)