]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109276: Enhance libregrtest results (#109828)
authorVictor Stinner <vstinner@python.org>
Mon, 25 Sep 2023 13:50:15 +0000 (15:50 +0200)
committerGitHub <noreply@github.com>
Mon, 25 Sep 2023 13:50:15 +0000 (13:50 +0000)
* Factorize code listing "bad / env changed / ..." tests.
* Add TestResults.is_all_good() method.
* Move "All 400 tests OK." to the end
* Move "Test suite interrupted by signal SIGINT." to the end.

Lib/test/libregrtest/results.py
Lib/test/test_regrtest.py

index 6e7d65880f734764f5c95ad349c429489f732151..fc4c547b34ac755f17c45be1177945947ceb34b7 100644 (file)
@@ -33,6 +33,11 @@ class TestResults:
         # used by --junit-xml
         self.testsuite_xml: list[str] = []
 
+    def is_all_good(self):
+        return (not self.bad
+                and not self.skipped
+                and not self.interrupted)
+
     def get_executed(self):
         return (set(self.good) | set(self.bad) | set(self.skipped)
                 | set(self.resource_denied) | set(self.env_changed)
@@ -164,24 +169,12 @@ class TestResults:
                 f.write(s)
 
     def display_result(self, tests: TestTuple, quiet: bool, print_slowest: bool):
-        if self.interrupted:
-            print("Test suite interrupted by signal SIGINT.")
-
         omitted = set(tests) - self.get_executed()
         if omitted:
             print()
             print(count(len(omitted), "test"), "omitted:")
             printlist(omitted)
 
-        if self.good and not quiet:
-            print()
-            if (not self.bad
-                and not self.skipped
-                and not self.interrupted
-                and len(self.good) > 1):
-                print("All", end=' ')
-            print(count(len(self.good), "test"), "OK.")
-
         if print_slowest:
             self.test_times.sort(reverse=True)
             print()
@@ -189,36 +182,34 @@ class TestResults:
             for test_time, test in self.test_times[:10]:
                 print("- %s: %s" % (test, format_duration(test_time)))
 
-        if self.bad:
-            print()
-            print(count(len(self.bad), "test"), "failed:")
-            printlist(self.bad)
-
-        if self.env_changed:
-            print()
-            print("{} altered the execution environment:".format(
-                     count(len(self.env_changed), "test")))
-            printlist(self.env_changed)
-
-        if self.skipped and not quiet:
-            print()
-            print(count(len(self.skipped), "test"), "skipped:")
-            printlist(self.skipped)
-
-        if self.resource_denied and not quiet:
-            print()
-            print(count(len(self.resource_denied), "test"), "skipped (resource denied):")
-            printlist(self.resource_denied)
+        all_tests = [
+            (self.bad, "test", "{} failed:"),
+            (self.env_changed, "test", "{} altered the execution environment (env changed):"),
+        ]
+        if not quiet:
+            all_tests.append((self.skipped, "test", "{} skipped:"))
+            all_tests.append((self.resource_denied, "test", "{} skipped (resource denied):"))
+        all_tests.append((self.rerun, "re-run test", "{}:"))
+        all_tests.append((self.run_no_tests, "test", "{} run no tests:"))
+
+        for tests_list, count_text, title_format in all_tests:
+            if tests_list:
+                print()
+                count_text = count(len(tests_list), count_text)
+                print(title_format.format(count_text))
+                printlist(tests_list)
 
-        if self.rerun:
+        if self.good and not quiet:
             print()
-            print("%s:" % count(len(self.rerun), "re-run test"))
-            printlist(self.rerun)
+            text = count(len(self.good), "test")
+            text = f"{text} OK."
+            if (self.is_all_good() and len(self.good) > 1):
+                text = f"All {text}"
+            print(text)
 
-        if self.run_no_tests:
+        if self.interrupted:
             print()
-            print(count(len(self.run_no_tests), "test"), "run no tests:")
-            printlist(self.run_no_tests)
+            print("Test suite interrupted by signal SIGINT.")
 
     def display_summary(self, first_runtests: RunTests, filtered: bool):
         # Total tests
index 408e667fffa0f0ae6b8b23ef9e40eafa0ab5047c..4100c98839b55fa4025811ad9049d5f47e72aaa5 100644 (file)
@@ -500,7 +500,8 @@ class BaseTestCase(unittest.TestCase):
             self.check_line(output, regex)
 
         if env_changed:
-            regex = list_regex('%s test%s altered the execution environment',
+            regex = list_regex(r'%s test%s altered the execution environment '
+                               r'\(env changed\)',
                                env_changed)
             self.check_line(output, regex)