[PATCH 01/15] unittests: unittest_helper: store verbosity at the environment

Mauro Carvalho Chehab posted 15 patches 4 days, 21 hours ago
[PATCH 01/15] unittests: unittest_helper: store verbosity at the environment
Posted by Mauro Carvalho Chehab 4 days, 21 hours ago
As tests may want to add their own verbosed messages, pass
the defined verbosity level to the test classes via env.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 tools/lib/python/unittest_helper.py | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/tools/lib/python/unittest_helper.py b/tools/lib/python/unittest_helper.py
index d2efb78d8561..55d444cd73d4 100755
--- a/tools/lib/python/unittest_helper.py
+++ b/tools/lib/python/unittest_helper.py
@@ -279,14 +279,19 @@ class TestUnits:
         if not caller_file and not suite:
             raise TypeError("Either caller_file or suite is needed at TestUnits")
 
-        if env:
-            patcher = patch.dict(os.environ, env)
-            patcher.start()
-            # ensure it gets stopped after
-            atexit.register(patcher.stop)
-
         verbose = args.verbose
 
+        if not env:
+            env = os.environ.copy()
+
+        env["VERBOSE"] = f"{verbose}"
+
+        patcher = patch.dict(os.environ, env)
+        patcher.start()
+        # ensure it gets stopped after
+        atexit.register(patcher.stop)
+
+
         if verbose >= 2:
             unittest.TextTestRunner(verbosity=verbose).run = lambda suite: suite
 
-- 
2.52.0