2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Implements a unittest TestRunner with GTest output.
8 This output is ported from gtest.cc's PrettyUnitTestResultPrinter, but
9 designed to be a drop-in replacement for unittest's TextTestRunner.
16 from telemetry.unittest import gtest_unittest_results
19 class GTestTestSuite(unittest.TestSuite):
20 def __call__(self, *args, **kwargs):
22 timestamp = time.time()
23 unit = 'test' if len(self._tests) == 1 else 'tests'
24 if not any(isinstance(x, unittest.TestSuite) for x in self._tests):
25 print '[----------] %d %s' % (len(self._tests), unit)
26 for test in self._tests:
31 ms = (endts - timestamp) * 1000
32 if not any(isinstance(x, unittest.TestSuite) for x in self._tests):
33 print '[----------] %d %s (%d ms total)' % (len(self._tests), unit, ms)
38 class GTestTestRunner(object):
39 def __init__(self, print_result_after_run=True):
40 self.print_result_after_run = print_result_after_run
41 self.result = gtest_unittest_results.GTestUnittestResults(sys.stdout)
44 "Run the given test case or test suite."
46 if self.print_result_after_run:
47 self.result.PrintSummary()