[PATCH v3 3/4] tests/functional: add --list-tests CLI arg

Manos Pitsidianakis posted 4 patches 3 months, 3 weeks ago
Maintainers: Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, "Daniel P. Berrangé" <berrange@redhat.com>
[PATCH v3 3/4] tests/functional: add --list-tests CLI arg
Posted by Manos Pitsidianakis 3 months, 3 weeks ago
Add CLI argument to list tests and exit.

Example output (current dir is build directory under root dir):

  $ export PYTHONPATH=../python:../tests/functional
  $ export QEMU_TEST_QEMU_BINARY="$(pwd)/qemu-system-aarch64"
  $ ./pyvenv/bin/python3 ../tests/functional/test_aarch64_virt.py --list-tests
  test_aarch64_virt_gicv2 (test_aarch64_virt.Aarch64VirtMachine.test_aarch64_virt_gicv2)
  test_aarch64_virt_gicv3 (test_aarch64_virt.Aarch64VirtMachine.test_aarch64_virt_gicv3)
  test_alpine_virt_tcg_gic_max (test_aarch64_virt.Aarch64VirtMachine.test_alpine_virt_tcg_gic_max)

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
---
 tests/functional/qemu_test/testcase.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
index f7e306cf749e8b24a712b09dfe8673660cbb5085..ab564f873c303bcc28c3bf7bec8c8c4569fae91c 100644
--- a/tests/functional/qemu_test/testcase.py
+++ b/tests/functional/qemu_test/testcase.py
@@ -36,6 +36,7 @@
 class QemuBaseTest(unittest.TestCase):
     debug: bool = False
     keep_scratch: bool = "QEMU_TEST_KEEP_SCRATCH" in os.environ
+    list_tests: bool = False
 
     """
     Class method that initializes class attributes from given command-line
@@ -61,9 +62,15 @@ def parse_args():
             "This is equivalent to setting QEMU_TEST_KEEP_SCRATCH=1 in the "
             "environment.",
         )
+        parser.add_argument(
+            "--list-tests",
+            action="store_true",
+            help="List all tests that would be executed and exit.",
+        )
         args = parser.parse_args()
         QemuBaseTest.debug = args.debug
         QemuBaseTest.keep_scratch |= args.keep_scratch
+        QemuBaseTest.list_tests = args.list_tests
         return
 
     '''
@@ -292,6 +299,13 @@ def main():
         path = os.path.basename(sys.argv[0])[:-3]
         QemuBaseTest.parse_args()
 
+        if QemuBaseTest.list_tests:
+            loader = unittest.TestLoader()
+            for test_suite in loader.loadTestsFromName(path):
+                for test in test_suite:
+                    print(test)
+            return
+
         cache = os.environ.get("QEMU_TEST_PRECACHE", None)
         if cache is not None:
             Asset.precache_suites(path, cache)

-- 
2.47.2