From ce7a67e511467f72c52c950fb0e0c48a69054974 Mon Sep 17 00:00:00 2001
From: Eli Schwartz <eschwartz@archlinux.org>
Date: Sun, 20 Mar 2022 00:54:56 -0400
Subject: project tests: do not use tqdm progress bars for a single test

This can happen for example with `--only fpga` as that category has
exactly one test.
---
 run_project_tests.py | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

(limited to 'run_project_tests.py')

diff --git a/run_project_tests.py b/run_project_tests.py
index e08d0cd..ed09870 100755
--- a/run_project_tests.py
+++ b/run_project_tests.py
@@ -1230,19 +1230,21 @@ def _run_tests(all_tests: T.List[T.Tuple[str, T.List[TestDef], bool]],
     # Ensure we only cancel once
     tests_canceled = False
 
-    # Optionally enable the tqdm progress bar
+    # Optionally enable the tqdm progress bar, but only if there is at least
+    # one LogRunFuture and one TestRunFuture
     global safe_print
     futures_iter: T.Iterable[RunFutureUnion] = futures
-    try:
-        from tqdm import tqdm
-        futures_iter = tqdm(futures, desc='Running tests', unit='test')
+    if len(futures) > 2:
+        try:
+            from tqdm import tqdm
+            futures_iter = tqdm(futures, desc='Running tests', unit='test')
 
-        def tqdm_print(*args: mlog.TV_Loggable, sep: str = ' ') -> None:
-            tqdm.write(sep.join([str(x) for x in args]))
+            def tqdm_print(*args: mlog.TV_Loggable, sep: str = ' ') -> None:
+                tqdm.write(sep.join([str(x) for x in args]))
 
-        safe_print = tqdm_print
-    except ImportError:
-        pass
+            safe_print = tqdm_print
+        except ImportError:
+            pass
 
     # Wait and handle the test results and print the stored log output
     for f in futures_iter:
-- 
cgit v1.1