[v2,3/4] testsuite: run Python unittests in fast suite

Message ID 20261026143132.1067398-3-clara.kowalsky@siemens.com
State New
Headers show
Series [v2,1/4] testsuite: fix run_privileged_cmd in image account extension unit test | expand

Commit Message

Clara Kowalsky Oct. 26, 2026, 2:31 p.m. UTC
Add an Avocado test with tag fast to run the Python unittests.
By default, all unittests located in testsuite/unittests/test* are run.
It is also possible to run a specific test or test file.

Signed-off-by: Clara Kowalsky <clara.kowalsky@siemens.com>
---
 testsuite/citest.py | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

Patch

diff --git a/testsuite/citest.py b/testsuite/citest.py
index 245a4305..dd151c1c 100644
--- a/testsuite/citest.py
+++ b/testsuite/citest.py
@@ -8,7 +8,7 @@ 
 
 from avocado import skipUnless
 from avocado.core import exceptions
-from avocado.utils import path
+from avocado.utils import path, process
 from cibase import CIBaseTest
 from utils import CIUtils
 
@@ -56,6 +56,23 @@  class EnvTest(CIBaseTest):
         self.perform_build_test(targets)
 
 
+class UnittestTest(CIBaseTest):
+    """Run the Python unit tests.
+
+    :avocado: tags=unittest,fast
+    """
+
+    def test_unittest(self):
+        test = self.params.get('test', default='')
+        if test:
+            process.run(
+                f'python3 -m unittest {test}',
+                env={'PYTHONPATH': 'testsuite/unittests'},
+            )
+        else:
+            process.run('python3 -m unittest discover -s testsuite/unittests')
+
+
 class DevTest(CIBaseTest):
 
     """