diff options
author | Victor Stinner <vstinner@python.org> | 2023-09-25 13:50:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-25 13:50:15 (GMT) |
commit | faebed4a67073a9206c3535d2699d783451ea251 (patch) | |
tree | fbd43b9393ad5f188ad342fbdfa4ae85500ae2e0 | |
parent | f29bc9c9a0a6794c6b8a9e84a7ba9237b427a10a (diff) | |
download | cpython-faebed4a67073a9206c3535d2699d783451ea251.zip cpython-faebed4a67073a9206c3535d2699d783451ea251.tar.gz cpython-faebed4a67073a9206c3535d2699d783451ea251.tar.bz2 |
gh-109276: Enhance libregrtest results (#109828)
* 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.
-rw-r--r-- | Lib/test/libregrtest/results.py | 67 | ||||
-rw-r--r-- | Lib/test/test_regrtest.py | 3 |
2 files changed, 31 insertions, 39 deletions
diff --git a/Lib/test/libregrtest/results.py b/Lib/test/libregrtest/results.py index 6e7d658..fc4c547 100644 --- a/Lib/test/libregrtest/results.py +++ b/Lib/test/libregrtest/results.py @@ -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 diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py index 408e667..4100c98 100644 --- a/Lib/test/test_regrtest.py +++ b/Lib/test/test_regrtest.py @@ -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) |