一种想法

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)
posted @ 2014-06-15 18:49  tim胖  阅读(162)  评论(0编辑  收藏  举报