diff --git a/gtest_parallel.py b/gtest_parallel.py index ac29114..c9ed770 100755 --- a/gtest_parallel.py +++ b/gtest_parallel.py @@ -243,6 +243,7 @@ def run(self, timeout_per_test): try: self.exit_code = sigint_handler.wait(task, timeout_per_test) except sigint_handler.ProcessWasInterrupted: + self.runtime_ms = int(1000 * (time.time() - begin)) thread.exit() self.runtime_ms = int(1000 * (time.time() - begin)) self.last_execution_time = None if self.exit_code else self.runtime_ms @@ -359,9 +360,13 @@ def print_tests(self, message, tasks, print_try_number, print_test_command): self.out.permanent_line("%s (%s/%s):" % (message, len(tasks), self.total_tasks)) for task in sorted(tasks): - runtime_ms = 'Interrupted' - if task.runtime_ms is not None: + if message == 'INTERRUPTED TESTS': + runtime_ms = ('Interrupted: %d ms' % task.runtime_ms + if task.runtime_ms is not None else 'Interrupted') + elif task.runtime_ms is not None: runtime_ms = '%d ms' % task.runtime_ms + else: + runtime_ms = 'Interrupted' if print_test_command: try: cmd_str = " ".join(task.test_command) diff --git a/gtest_parallel_tests.py b/gtest_parallel_tests.py index 6613d72..9ee34cb 100755 --- a/gtest_parallel_tests.py +++ b/gtest_parallel_tests.py @@ -423,6 +423,8 @@ def run_test(_): self.assertTrue(os.path.isfile(task.log_file)) self.assertIsNone(task.exit_code) + self.assertIsNotNone(task.runtime_ms) + self.assertGreaterEqual(task.runtime_ms, 0) self._execute_run_test(run_test, True) @@ -504,6 +506,38 @@ def run_test(logger): self._execute_test(run_test, False) + def test_print_interrupted_tests_shows_runtime(self): + class StdoutCapture(object): + def __init__(self): + self.lines = [] + + def isatty(self): + return False + + def write(self, msg): + self.lines.append(msg) + + def flush(self): + pass + + stdout = StdoutCapture() + with guard_patch_module('sys.stdout', stdout): + logger = gtest_parallel.FilterFormat(None) + logger.log_tasks(1) + interrupted = [ + TaskMock( + ('fake/binary', 'FakeTest'), 0, { + 'runtime_ms': [1078216], + 'exit_code': [None], + 'last_execution_time': [None], + }) + ] + logger.print_tests('INTERRUPTED TESTS', interrupted, + print_try_number=False, print_test_command=False) + + output = ''.join(stdout.lines) + self.assertIn('Interrupted: 1078216 ms: fake/binary FakeTest', output) + class TestFindTests(unittest.TestCase): ONE_DISABLED_ONE_ENABLED_TEST = {