Skip to content

Commit

Permalink
pythongh-129363: Change regrtest sequential mode output
Browse files Browse the repository at this point in the history
First, write the test name without color. Then, write the test name
and the result with color. Each test is displayed twice.
  • Loading branch information
vstinner committed Jan 30, 2025
1 parent 4e47e05 commit c4f338d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
21 changes: 6 additions & 15 deletions Lib/test/libregrtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,11 @@ def run_tests_sequentially(self, runtests: RunTests) -> None:
msg += " (timeout: %s)" % format_duration(runtests.timeout)
self.log(msg)

previous_test = None
tests_iter = runtests.iter_tests()
for test_index, test_name in enumerate(tests_iter, 1):
start_time = time.perf_counter()

text = test_name
if previous_test:
text = '%s -- %s' % (text, previous_test)
self.logger.display_progress(test_index, text)
self.logger.display_progress(test_index, test_name)

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

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

if result.must_stop(self.fail_fast, self.fail_env_changed):
break

previous_test = str(result)
text = str(result)
test_time = time.perf_counter() - start_time
if test_time >= PROGRESS_MIN_TIME:
previous_test = "%s in %s" % (previous_test, format_duration(test_time))
elif result.state == State.PASSED:
# be quiet: say nothing if the test passed shortly
previous_test = None
text = f"{text} in {format_duration(test_time)}"
self.logger.display_progress(test_index, text)

if previous_test:
print(previous_test)
if result.must_stop(self.fail_fast, self.fail_env_changed):
break

def get_state(self) -> str:
state = self.results.get_state(self.fail_env_changed)
Expand Down
15 changes: 13 additions & 2 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@
ROOT_DIR = os.path.join(os.path.dirname(__file__), '..', '..')
ROOT_DIR = os.path.abspath(os.path.normpath(ROOT_DIR))
LOG_PREFIX = r'[0-9]+:[0-9]+:[0-9]+ (?:load avg: [0-9]+\.[0-9]{2} )?'
RESULT_REGEX = (
'passed',
'failed',
'skipped',
'interrupted',
'env changed',
'timed out',
'ran no tests',
'worker non-zero exit code',
)
RESULT_REGEX = fr'(?:{"|".join(RESULT_REGEX)})'

EXITCODE_BAD_TEST = 2
EXITCODE_ENV_CHANGED = 3
Expand Down Expand Up @@ -555,8 +566,8 @@ def check_line(self, output, pattern, full=False, regex=True):
self.assertRegex(output, regex)

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

Expand Down

0 comments on commit c4f338d

Please sign in to comment.