Skip to content

Commit c4f338d

Browse files
committed
pythongh-129363: Change regrtest sequential mode output
First, write the test name without color. Then, write the test name and the result with color. Each test is displayed twice.
1 parent 4e47e05 commit c4f338d

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
@@ -393,15 +393,11 @@ def run_tests_sequentially(self, runtests: RunTests) -> None:
393393
msg += " (timeout: %s)" % format_duration(runtests.timeout)
394394
self.log(msg)
395395

396-
previous_test = None
397396
tests_iter = runtests.iter_tests()
398397
for test_index, test_name in enumerate(tests_iter, 1):
399398
start_time = time.perf_counter()
400399

401-
text = test_name
402-
if previous_test:
403-
text = '%s -- %s' % (text, previous_test)
404-
self.logger.display_progress(test_index, text)
400+
self.logger.display_progress(test_index, test_name)
405401

406402
result = self.run_test(test_name, runtests, tracer)
407403

@@ -418,19 +414,14 @@ def run_tests_sequentially(self, runtests: RunTests) -> None:
418414
except (KeyError, AttributeError):
419415
pass
420416

421-
if result.must_stop(self.fail_fast, self.fail_env_changed):
422-
break
423-
424-
previous_test = str(result)
417+
text = str(result)
425418
test_time = time.perf_counter() - start_time
426419
if test_time >= PROGRESS_MIN_TIME:
427-
previous_test = "%s in %s" % (previous_test, format_duration(test_time))
428-
elif result.state == State.PASSED:
429-
# be quiet: say nothing if the test passed shortly
430-
previous_test = None
420+
text = f"{text} in {format_duration(test_time)}"
421+
self.logger.display_progress(test_index, text)
431422

432-
if previous_test:
433-
print(previous_test)
423+
if result.must_stop(self.fail_fast, self.fail_env_changed):
424+
break
434425

435426
def get_state(self) -> str:
436427
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)