Bug 1753795 - Add progress bar (via tqdm) to running Python Tests r=ahal

This will give additional feedback to the user. Now they will have
immediate feedback in regards to the progress of the test run, instead
of being unsure of what's happening until the first test run completes.

Differential Revision: https://phabricator.services.mozilla.com/D137925
This commit is contained in:
ahochheiden 2022-02-11 18:51:46 +00:00
parent 0f69196034
commit f405f02655

View File

@ -12,6 +12,7 @@ import subprocess
from multiprocessing import cpu_count
from concurrent.futures import ThreadPoolExecutor, as_completed, thread
from tqdm import tqdm
import mozinfo
from mozfile import which
@ -160,7 +161,6 @@ def run_python_tests(
extra=None,
**kwargs,
):
command_context.activate_virtualenv()
if test_objects is None:
from moztest.resolve import TestResolver
@ -249,53 +249,65 @@ def run_python_tests(
return return_code or ret
try:
with ThreadPoolExecutor(max_workers=jobs) as executor:
futures = []
with tqdm(
total=(len(parallel) + len(sequential)),
unit="Test",
desc="Tests Completed",
initial=0,
) as progress_bar:
try:
with ThreadPoolExecutor(max_workers=jobs) as executor:
futures = []
for test in parallel:
command_context.log(
logging.DEBUG,
"python-test",
{"line": f"Launching thread for test {test['file_relpath']}"},
"{line}",
)
futures.append(
executor.submit(
_run_python_test, command_context, test, jobs, verbose
for test in parallel:
command_context.log(
logging.DEBUG,
"python-test",
{"line": f"Launching thread for test {test['file_relpath']}"},
"{line}",
)
futures.append(
executor.submit(
_run_python_test, command_context, test, jobs, verbose
)
)
try:
for future in as_completed(futures):
progress_bar.clear()
return_code = on_test_finished(future.result())
progress_bar.update(1)
except KeyboardInterrupt:
# Hack to force stop currently running threads.
# https://gist.github.com/clchiou/f2608cbe54403edb0b13
executor._threads.clear()
thread._threads_queues.clear()
raise
for test in sequential:
test_result = _run_python_test(command_context, test, jobs, verbose)
progress_bar.clear()
return_code = on_test_finished(test_result)
if return_code and exitfirst:
break
progress_bar.update(1)
finally:
progress_bar.clear()
# Now log all failures (even if there was a KeyboardInterrupt or other exception).
for line in failure_output:
command_context.log(
logging.INFO, "python-test", {"line": line.rstrip()}, "{line}"
)
try:
for future in as_completed(futures):
return_code = on_test_finished(future.result())
except KeyboardInterrupt:
# Hack to force stop currently running threads.
# https://gist.github.com/clchiou/f2608cbe54403edb0b13
executor._threads.clear()
thread._threads_queues.clear()
raise
for test in sequential:
return_code = on_test_finished(
_run_python_test(command_context, test, jobs, verbose)
)
if return_code and exitfirst:
break
finally:
# Now log failed tests (even if there was a KeyboardInterrupt or other
# exception).
for line in failure_output:
command_context.log(
logging.INFO, "python-test", {"line": line.rstrip()}, "{line}"
)
command_context.log(
logging.INFO,
"python-test",
{"return_code": return_code},
"Return code from mach python-test: {return_code}",
)
return return_code