diff options
| author | Mauro Carvalho Chehab <mchehab+huawei@kernel.org> | 2026-03-26 20:09:42 +0100 |
|---|---|---|
| committer | Jonathan Corbet <corbet@lwn.net> | 2026-03-30 10:54:13 -0600 |
| commit | 07f6cb18c5dd627023e0810cfd51203392f55990 (patch) | |
| tree | 149efd2618ef9142b00df600673f4700ef405a64 /tools/lib/python | |
| parent | ece7e57afd51e0b807bef5a43e2d0b1cd6e9c86f (diff) | |
tools: unittest_helper: add a quiet mode
On quiet mode, only report errors.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Message-ID: <27556792ff70e6267ecd19c258149d380db8d423.1774551940.git.mchehab+huawei@kernel.org>
Diffstat (limited to 'tools/lib/python')
| -rwxr-xr-x | tools/lib/python/unittest_helper.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/tools/lib/python/unittest_helper.py b/tools/lib/python/unittest_helper.py index 55d444cd73d46..f3cba51204019 100755 --- a/tools/lib/python/unittest_helper.py +++ b/tools/lib/python/unittest_helper.py @@ -141,7 +141,7 @@ class Summary(unittest.TestResult): super().addSkip(test, reason) self._record_test(test, f"SKIP ({reason})") - def printResults(self): + def printResults(self, verbose): """ Print results using colors if tty. """ @@ -174,10 +174,15 @@ class Summary(unittest.TestResult): # Print results for module_name, classes in self.test_results.items(): - print(f"{module_name}:") + if verbose: + print(f"{module_name}:") for class_name, tests in classes.items(): - print(f" {class_name}:") + if verbose: + print(f" {class_name}:") for test_name, status in tests: + if not verbose and status in [ "OK", "EXPECTED_FAIL" ]: + continue + # Get base status without reason for SKIP if status.startswith("SKIP"): status_code = status.split()[0] @@ -187,7 +192,8 @@ class Summary(unittest.TestResult): print( f" {test_name + ':':<{max_length}}{color}{status}{COLORS['reset']}" ) - print() + if verbose: + print() # Print summary print(f"\nRan {self.testsRun} tests", end="") @@ -230,6 +236,7 @@ class TestUnits: """Returns a parser for command line arguments.""" parser = argparse.ArgumentParser(description="Test runner with regex filtering") parser.add_argument("-v", "--verbose", action="count", default=1) + parser.add_argument("-q", "--quiet", action="store_true") parser.add_argument("-f", "--failfast", action="store_true") parser.add_argument("-k", "--keyword", help="Regex pattern to filter test methods") @@ -279,7 +286,10 @@ class TestUnits: if not caller_file and not suite: raise TypeError("Either caller_file or suite is needed at TestUnits") - verbose = args.verbose + if args.quiet: + verbose = 0 + else: + verbose = args.verbose if not env: env = os.environ.copy() @@ -334,7 +344,7 @@ class TestUnits: failfast=args.failfast) result = runner.run(suite) if resultclass: - result.printResults() + result.printResults(verbose) sys.exit(not result.wasSuccessful()) |
