diff mbox series

[04/14] lava_runner: respect to verbosity flag from unittest framework

Message ID 20230313094431.507952-5-tzungbi@kernel.org (mailing list archive)
State Handled Elsewhere
Headers show
Series cros-ec-tests: fix some exceptions and clean-ups | expand

Commit Message

Tzung-Bi Shih March 13, 2023, 9:44 a.m. UTC
testRunner in unittest.main() shouldn't be an instance.  Otherwise, any
verbosity flag won't pass into the testRunner.

For example:

1.
m = unittest.main(
	testRunner=TextTestRunner(...),
	verbosity=0
    )
The verbosity won't take effect in the TextTestRunner.  Instead, it uses
the default verbosity in TextTestRunner(), i.e., 1.

2.
m = unittest.main(
	testRunner=TextTestRunner(...),
    )
When invoking `python3 -m ... -q`, it intends to set the verbosity to 0.
However, the testRunner has been instantiated, the flag won't pass to
the testRunner.

Thus, LavaTestRunner is back.

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
 cros/runners/lava_runner.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/cros/runners/lava_runner.py b/cros/runners/lava_runner.py
index 70f8aa61132e..427d41f2eadb 100755
--- a/cros/runners/lava_runner.py
+++ b/cros/runners/lava_runner.py
@@ -1,6 +1,7 @@ 
 #!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
+import functools
 import sys
 import unittest
 
@@ -43,9 +44,15 @@  class LavaTestResult(unittest.TextTestResult):
         self.writeLavaSignal(test, "skip")
 
 
+class LavaTestRunner(unittest.TextTestRunner):
+    __init__ = functools.partialmethod(
+                    unittest.TextTestRunner.__init__,
+                    resultclass=LavaTestResult)
+
+
 if __name__ == "__main__":
     unittest.main(
-        testRunner=unittest.TextTestRunner(resultclass=LavaTestResult),
+        testRunner=LavaTestRunner,
         # these make sure that some options that are not applicable
         # remain hidden from the help menu.
         failfast=False,