diff --git a/tests/meson.build b/tests/meson.build
index 99b9bcb..cce5c04 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -26,12 +26,35 @@ if get_option('introspection')
envs.prepend('GI_TYPELIB_PATH', join_paths(meson.build_root(), 'libfprint'))
if 'virtual_image' in drivers
- test('virtual-image',
- find_program('virtual-image.py'),
- args: '--verbose',
- env: envs,
- depends: libfprint_typelib,
- )
+ python3 = find_program('python3')
+ unittest_inspector = find_program('unittest_inspector.py')
+ base_args = files('virtual-image.py')
+ suite = []
+
+ r = run_command(unittest_inspector, files('virtual-image.py'))
+ unit_tests = r.stdout().strip().split('\n')
+
+ if r.returncode() == 0 and unit_tests.length() > 0
+ suite += 'virtual-image'
+ else
+ unit_tests = ['virtual-image']
+ endif
+
+ foreach ut: unit_tests
+ ut_suite = suite
+ ut_args = base_args
+ if unit_tests.length() > 1
+ ut_args += ut
+ ut_suite += ut.split('.')[0]
+ endif
+ test(ut,
+ python3,
+ args: ut_args,
+ suite: ut_suite,
+ depends: libfprint_typelib,
+ env: envs,
+ )
+ endforeach
else
test('virtual-image',
find_program('sh'),
diff --git a/tests/unittest_inspector.py b/tests/unittest_inspector.py
new file mode 100755
index 0000000..0d5d3a6
--- /dev/null
+++ b/tests/unittest_inspector.py
@@ -0,0 +1,46 @@
+#! /usr/bin/env python3
+# Copyright © 2020, Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library. If not, see .
+# Authors:
+# Marco Trevisan
+
+import argparse
+import importlib.util
+import inspect
+import os
+import unittest
+
+def list_tests(module):
+ tests = []
+ for name, obj in inspect.getmembers(module):
+ if inspect.isclass(obj) and issubclass(obj, unittest.TestCase):
+ cases = unittest.defaultTestLoader.getTestCaseNames(obj)
+ tests += [ (obj, '{}.{}'.format(name, t)) for t in cases ]
+ return tests
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser()
+ parser.add_argument('unittest_source', type=argparse.FileType('r'))
+
+ args = parser.parse_args()
+ source_path = args.unittest_source.name
+ spec = importlib.util.spec_from_file_location(
+ os.path.basename(source_path), source_path)
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+
+ for machine, human in list_tests(module):
+ print(human)
diff --git a/tests/virtual-image.py b/tests/virtual-image.py
index 2440c6d..b6cad95 100755
--- a/tests/virtual-image.py
+++ b/tests/virtual-image.py
@@ -345,6 +345,6 @@ class VirtualImage(unittest.TestCase):
ctx.iteration(True)
assert(not self._verify_match)
-# avoid writing to stderr
-unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))
-
+if __name__ == '__main__':
+ # avoid writing to stderr
+ unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))