Skip to content

gh-129363: Added colored printing for python -m test without the -j flag #129364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions Lib/test/libregrtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,17 +393,19 @@ 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()
result = self.run_test(test_name, runtests, tracer)

text = test_name
if previous_test:
text = '%s -- %s' % (text, previous_test)
self.logger.display_progress(test_index, text)
text = str(result)
if (
result.duration
and result.duration >= PROGRESS_MIN_TIME
and not self.pgo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why check PGO? I don't think this was relevant before?

):
text += f" ({format_duration(result.duration)})"

result = self.run_test(test_name, runtests, tracer)
self.logger.display_progress(test_index, text)

# Unload the newly imported test modules (best effort finalization)
new_modules = [module for module in sys.modules
Expand All @@ -421,17 +423,6 @@ def run_tests_sequentially(self, runtests: RunTests) -> None:
if result.must_stop(self.fail_fast, self.fail_env_changed):
break

previous_test = 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

if previous_test:
print(previous_test)

def get_state(self) -> str:
state = self.results.get_state(self.fail_env_changed)
if self.first_state:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added colored printing for ``python -m test`` without the ``-j`` flag.
Loading