Skip to content

Commit 0831b54

Browse files
tdb3sipa
andcommitted
test: simplify test_runner.py
Remove the num_running variable as it can be implied by the length of the jobs list. Remove the i variable as it can be implied by the length of the test_results list. Instead of counting results to determine if finished, make the queue object itself responsible (by looking at running jobs and jobs left). Originally proposed by @sipa in PR bitcoin#23995. Co-authored-by: Pieter Wuille <[email protected]>
1 parent 1105aa4 commit 0831b54

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

test/functional/test_runner.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -614,14 +614,12 @@ def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=
614614
max_len_name = len(max(test_list, key=len))
615615
test_count = len(test_list)
616616
all_passed = True
617-
i = 0
618-
while i < test_count:
617+
while not job_queue.done():
619618
if failfast and not all_passed:
620619
break
621620
for test_result, testdir, stdout, stderr, skip_reason in job_queue.get_next():
622621
test_results.append(test_result)
623-
i += 1
624-
done_str = "{}/{} - {}{}{}".format(i, test_count, BOLD[1], test_result.name, BOLD[0])
622+
done_str = f"{len(test_results)}/{test_count} - {BOLD[1]}{test_result.name}{BOLD[0]}"
625623
if test_result.status == "Passed":
626624
logging.debug("%s passed, Duration: %s s" % (done_str, test_result.time))
627625
elif test_result.status == "Skipped":
@@ -706,14 +704,15 @@ def __init__(self, *, num_tests_parallel, tests_dir, tmpdir, test_list, flags, u
706704
self.tmpdir = tmpdir
707705
self.test_list = test_list
708706
self.flags = flags
709-
self.num_running = 0
710707
self.jobs = []
711708
self.use_term_control = use_term_control
712709

710+
def done(self):
711+
return not (self.jobs or self.test_list)
712+
713713
def get_next(self):
714-
while self.num_running < self.num_jobs and self.test_list:
714+
while len(self.jobs) < self.num_jobs and self.test_list:
715715
# Add tests
716-
self.num_running += 1
717716
test = self.test_list.pop(0)
718717
portseed = len(self.test_list)
719718
portseed_arg = ["--portseed={}".format(portseed)]
@@ -757,7 +756,6 @@ def get_next(self):
757756
skip_reason = re.search(r"Test Skipped: (.*)", stdout).group(1)
758757
else:
759758
status = "Failed"
760-
self.num_running -= 1
761759
self.jobs.remove(job)
762760
if self.use_term_control:
763761
clearline = '\r' + (' ' * dot_count) + '\r'

0 commit comments

Comments
 (0)