Skip to content

Commit f1b81c4

Browse files
vstinnerhugovk
andauthored
gh-129363: Change regrtest sequential mode output (#129476)
First, write the test name without color. Then, write the test name and the result with color. Each test is displayed twice. Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent c359fcd commit f1b81c4

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

Lib/test/libregrtest/main.py

+6-15
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,11 @@ def run_tests_sequentially(self, runtests: RunTests) -> None:
399399
msg += " (timeout: %s)" % format_duration(runtests.timeout)
400400
self.log(msg)
401401

402-
previous_test = None
403402
tests_iter = runtests.iter_tests()
404403
for test_index, test_name in enumerate(tests_iter, 1):
405404
start_time = time.perf_counter()
406405

407-
text = test_name
408-
if previous_test:
409-
text = '%s -- %s' % (text, previous_test)
410-
self.logger.display_progress(test_index, text)
406+
self.logger.display_progress(test_index, test_name)
411407

412408
result = self.run_test(test_name, runtests, tracer)
413409

@@ -424,19 +420,14 @@ def run_tests_sequentially(self, runtests: RunTests) -> None:
424420
except (KeyError, AttributeError):
425421
pass
426422

427-
if result.must_stop(self.fail_fast, self.fail_env_changed):
428-
break
429-
430-
previous_test = str(result)
423+
text = str(result)
431424
test_time = time.perf_counter() - start_time
432425
if test_time >= PROGRESS_MIN_TIME:
433-
previous_test = "%s in %s" % (previous_test, format_duration(test_time))
434-
elif result.state == State.PASSED:
435-
# be quiet: say nothing if the test passed shortly
436-
previous_test = None
426+
text = f"{text} in {format_duration(test_time)}"
427+
self.logger.display_progress(test_index, text)
437428

438-
if previous_test:
439-
print(previous_test)
429+
if result.must_stop(self.fail_fast, self.fail_env_changed):
430+
break
440431

441432
def get_state(self) -> str:
442433
state = self.results.get_state(self.fail_env_changed)

Lib/test/test_regrtest.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@
4242
ROOT_DIR = os.path.join(os.path.dirname(__file__), '..', '..')
4343
ROOT_DIR = os.path.abspath(os.path.normpath(ROOT_DIR))
4444
LOG_PREFIX = r'[0-9]+:[0-9]+:[0-9]+ (?:load avg: [0-9]+\.[0-9]{2} )?'
45+
RESULT_REGEX = (
46+
'passed',
47+
'failed',
48+
'skipped',
49+
'interrupted',
50+
'env changed',
51+
'timed out',
52+
'ran no tests',
53+
'worker non-zero exit code',
54+
)
55+
RESULT_REGEX = fr'(?:{"|".join(RESULT_REGEX)})'
4556

4657
EXITCODE_BAD_TEST = 2
4758
EXITCODE_ENV_CHANGED = 3
@@ -555,8 +566,8 @@ def check_line(self, output, pattern, full=False, regex=True):
555566
self.assertRegex(output, regex)
556567

557568
def parse_executed_tests(self, output):
558-
regex = (r'^%s\[ *[0-9]+(?:/ *[0-9]+)*\] (%s)'
559-
% (LOG_PREFIX, self.TESTNAME_REGEX))
569+
regex = (fr'^{LOG_PREFIX}\[ *[0-9]+(?:/ *[0-9]+)*\] '
570+
fr'({self.TESTNAME_REGEX}) {RESULT_REGEX}')
560571
parser = re.finditer(regex, output, re.MULTILINE)
561572
return list(match.group(1) for match in parser)
562573

0 commit comments

Comments
 (0)