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.
This commit is contained in:
Victor Stinner 2023-09-25 15:50:15 +02:00 committed by GitHub
parent f29bc9c9a0
commit faebed4a67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 38 deletions

View File

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

View File

@ -500,7 +500,8 @@ class BaseTestCase(unittest.TestCase):
self.check_line(output, regex) self.check_line(output, regex)
if env_changed: 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) env_changed)
self.check_line(output, regex) self.check_line(output, regex)