def run(self, test):
        "Run the given test case or test suite."
        result = self._makeResult()
        result.failfast = self.failfast
        result.buffer = self.buffer
        registerResult(result)

        startTime = time.time()
        startTestRun = getattr(result, 'startTestRun', None)
        if startTestRun is not None:
            startTestRun()
        try:
            test(result)
        finally:
            stopTestRun = getattr(result, 'stopTestRun', None)
            if stopTestRun is not None:
                stopTestRun()
            else:
                result.printErrors()
        stopTime = time.time()
        timeTaken = stopTime - startTime
        if hasattr(result, 'separator2'):
            self.stream.writeln(result.separator2)
        run = result.testsRun
        self.stream.writeln("Ran %d test%s in %.3fs" %
                            (run, run != 1 and "s" or "", timeTaken))
        self.stream.writeln()

        expectedFails = unexpectedSuccesses = skipped = 0
        try:
            results = map(len, (result.expectedFailures,
                                result.unexpectedSuccesses, result.skipped))
            expectedFails, unexpectedSuccesses, skipped = results
        except AttributeError:
            pass
        infos = []
        if not result.wasSuccessful():
            self.stream.write(SET_FAIL_OUTPUT + " FAILED " + RESET_OUTPUT)
            failed, errored = map(len, (result.failures, result.errors))
            if failed:
                infos.append("%sfailures=%d%s" %
                             (SET_FAILURE_TEXT, failed, RESET_OUTPUT))
            if errored:
                infos.append("%serrors=%d%s" %
                             (SET_ERROR_TEXT, errored, RESET_OUTPUT))
        else:
            self.stream.write(SET_OK_OUTPUT + " OK " + RESET_OUTPUT)
        if skipped:
            infos.append("skipped=%d" % skipped)
        if expectedFails:
            infos.append("expected failures=%d" % expectedFails)
        if unexpectedSuccesses:
            infos.append("unexpected successes=%d" % unexpectedSuccesses)
        if infos:
            self.stream.writeln(" (%s)" % (", ".join(infos), ))
        else:
            self.stream.write("\n")

        result.closeLogFiles()
        return result
Ejemplo n.º 2
0
 def run(self, test):
     "Run the given test case or test suite."
     result = self._makeResult()
     result.failfast = self.failfast
     result.buffer = self.buffer
     registerResult(result)
     
     startTime = time.time()
     startTestRun = getattr(result, 'startTestRun', None)
     if startTestRun is not None:
         startTestRun()
     try:
         test(result)
     finally:
         stopTestRun = getattr(result, 'stopTestRun', None)
         if stopTestRun is not None:
             stopTestRun()
         else:
             result.printErrors()
     stopTime = time.time()
     timeTaken = stopTime - startTime
     if hasattr(result, 'separator2'):
         self.stream.writeln(result.separator2)
     run = result.testsRun
     self.stream.writeln("Ran %d test%s in %.3fs" %
                         (run, run != 1 and "s" or "", timeTaken))
     self.stream.writeln()
     
     expectedFails = unexpectedSuccesses = skipped = 0
     try:
         results = map(len, (result.expectedFailures,
                             result.unexpectedSuccesses,
                             result.skipped))
         expectedFails, unexpectedSuccesses, skipped = results
     except AttributeError:
         pass
     infos = []
     if not result.wasSuccessful():
         self.stream.write("FAILED")
         failed, errored = map(len, (result.failures, result.errors))
         if failed:
             infos.append("failures=%d" % failed)
         if errored:
             infos.append("errors=%d" % errored)
     else:
         self.stream.write("OK")
     if skipped:
         infos.append("skipped=%d" % skipped)
     if expectedFails:
         infos.append("expected failures=%d" % expectedFails)
     if unexpectedSuccesses:
         infos.append("unexpected successes=%d" % unexpectedSuccesses)
     if infos:
         self.stream.writeln(" (%s)" % (", ".join(infos),))
     else:
         self.stream.write("\n")
     return result
    def run(self, test):
        "Run the given test case or test suite."
        result = self._makeResult()
        result.failfast = self.failfast
        result.buffer = self.buffer
        registerResult(result)

        startTime = time.time()
        startTestRun = getattr(result, 'startTestRun', None)
        if startTestRun is not None:
            startTestRun()
        try:
            test(result)
        finally:
            stopTestRun = getattr(result, 'stopTestRun', None)
            if stopTestRun is not None:
                stopTestRun()
            else:
                result.printErrors()
        stopTime = time.time()
        timeTaken = stopTime - startTime
        if hasattr(result, 'separator2'):
            self.stream.writeln(result.separator2)
        run = result.testsRun
        self.stream.writeln("Ran %d test%s in %.3fs" %
                            (run, run != 1 and "s" or "", timeTaken))
        self.stream.writeln()

        expectedFails = unexpectedSuccesses = skipped = 0
        try:
            results = list(
                map(
                    len, (
                        result.expectedFailures,
                        result.unexpectedSuccesses,
                        result.skipped
                    )
                )
            )
            expectedFails, unexpectedSuccesses, skipped = results
        except AttributeError:
            pass
        infos = []
        if not result.wasSuccessful():
            self.stream.write(SET_FAIL_OUTPUT + " FAILED " + RESET_OUTPUT)
            failed, errored = list(map(len, (result.failures, result.errors)))
            if failed:
                infos.append("%sfailures=%d%s" % (SET_FAILURE_TEXT, failed, RESET_OUTPUT))
            if errored:
                infos.append("%serrors=%d%s" % (SET_ERROR_TEXT, errored, RESET_OUTPUT))
        else:
            self.stream.write(SET_OK_OUTPUT + " OK " + RESET_OUTPUT)
        if skipped:
            infos.append("skipped=%d" % skipped)
        if expectedFails:
            infos.append("expected failures=%d" % expectedFails)
        if unexpectedSuccesses:
            infos.append("unexpected successes=%d" % unexpectedSuccesses)
        if infos:
            self.stream.writeln(" (%s)" % (", ".join(infos),))
        else:
            self.stream.write("\n")

        if result.slow_tests:
            self.stream.writeln("Slow tests: ")
        for test in result.slow_tests:
            self.stream.writeln(
                "{0} : {1}".format(test['name'], result.format_time(test['elapsed']))
            )

        result.closeLogFiles()
        return result