diff mbox series

[RFC,3/6] patchtest: allow to silence non-error messages

Message ID 20250203-b4-patchtest-v1-3-ef6ee5fcdd78@cherry.de
State New
Headers show
Series prepare patchtest to be run with b4 prep --check | expand

Commit Message

Quentin Schulz Feb. 3, 2025, 4 p.m. UTC
From: Quentin Schulz <quentin.schulz@cherry.de>

When passing --quiet to patchtest, TinFoil and Knotty will be silenced
so almost nothing makes it to stdout/stderr if not required (e.g. an
error happens).

patchtest configures its own logger to the ERROR level for the same
effect.

Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de>
---
 meta/lib/patchtest/patchtest_parser.py | 4 ++++
 meta/lib/patchtest/tests/base.py       | 2 +-
 scripts/patchtest                      | 4 +++-
 3 files changed, 8 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/meta/lib/patchtest/patchtest_parser.py b/meta/lib/patchtest/patchtest_parser.py
index 2a11cb76c2364e768bdb4c1fc050c84221428a4a..66c54628466b0234f8492f0a7d8ddbe59f5f7582 100644
--- a/meta/lib/patchtest/patchtest_parser.py
+++ b/meta/lib/patchtest/patchtest_parser.py
@@ -69,6 +69,10 @@  class PatchtestParser(object):
                             action='store_true',
                             help='Enable debug output')
 
+        parser.add_argument('--quiet', '-q',
+                            action='store_true',
+                            help='Only output error messages')
+
         parser.add_argument('--log-results', 
                             action='store_true', 
                             help='Enable logging to a file matching the target patch name with ".testresult" appended')
diff --git a/meta/lib/patchtest/tests/base.py b/meta/lib/patchtest/tests/base.py
index 919ca136bb469eee3e5af4b145e8293588728f84..7844e1c9e9f05e0a5c19eaaaa6a4267b10f96c0f 100644
--- a/meta/lib/patchtest/tests/base.py
+++ b/meta/lib/patchtest/tests/base.py
@@ -170,7 +170,7 @@  class Metadata(Base):
                 return tinfoil
             os.chdir(builddir)
             tinfoil = bb.tinfoil.Tinfoil()
-            tinfoil.prepare(config_only=config_only)
+            tinfoil.prepare(config_only=config_only, quiet=2 if PatchtestParser.quiet else 0)
         except bb.tinfoil.TinfoilUIException as te:
             if tinfoil:
                 tinfoil.shutdown()
diff --git a/scripts/patchtest b/scripts/patchtest
index 66a9f6470ca860c2233fb9ace042edf4b4737c88..6efd69465ef8d8dc6fa459d05220ccd08ca28536 100755
--- a/scripts/patchtest
+++ b/scripts/patchtest
@@ -139,7 +139,7 @@  def _runner(resultklass, prefix=None):
     # if there are no test cases, just quit
     if not ntc:
         return 2
-    runner = unittest.TextTestRunner(resultclass=resultklass, verbosity=0)
+    runner = unittest.TextTestRunner(stream=open(os.devnull, 'w') if PatchtestParser.quiet else None, resultclass=resultklass, verbosity=0)
 
     try:
         result = runner.run(suite)
@@ -243,6 +243,8 @@  if __name__ == '__main__':
     # set debugging level
     if PatchtestParser.debug:
         logger.setLevel(logging.DEBUG)
+    if PatchtestParser.quiet:
+        logger.setLevel(logging.ERROR)
 
     # if topdir not define, default it to testdir
     if not PatchtestParser.topdir: