diff options
author | Joerg Hofrichter <joerg.hofrichter@ni.com> | 2020-01-22 11:54:22 +0100 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2020-01-22 12:19:03 -0800 |
commit | 6ee886cfe222aa9282d9f1aa74565a145d333fae (patch) | |
tree | 3ef01b9c15788f393cc9d2dfb36119164614bf86 /mpm/python | |
parent | 674ace7b850799f4143b69b876606da7437028c3 (diff) | |
download | uhd-6ee886cfe222aa9282d9f1aa74565a145d333fae.tar.gz uhd-6ee886cfe222aa9282d9f1aa74565a145d333fae.tar.bz2 uhd-6ee886cfe222aa9282d9f1aa74565a145d333fae.zip |
mpm: optionally generate XML report when running unittests
If the unittests are invoked with an extra argument -x, an XML report
is generated if the xmlrunner module is installed
Diffstat (limited to 'mpm/python')
-rwxr-xr-x | mpm/python/tests/run_unit_tests.py | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/mpm/python/tests/run_unit_tests.py b/mpm/python/tests/run_unit_tests.py index d7c288aaa..26fc0e1fb 100755 --- a/mpm/python/tests/run_unit_tests.py +++ b/mpm/python/tests/run_unit_tests.py @@ -9,13 +9,28 @@ USRP MPM Python Unit testing framework import unittest import sys +import argparse from sys_utils_tests import TestNet +import importlib.util +if importlib.util.find_spec("xmlrunner"): + from xmlrunner import XMLTestRunner + TESTS = { '__all__': {TestNet}, 'n3xx': set(), } +def parse_args(): + """Parse arguments when running this as a script""" + parser_help = 'Run MPM Python unittests' + parser = argparse.ArgumentParser(description=parser_help) + parser.add_argument('-x', '--xml', dest='xml', action='store_true', default=False, + help='Generate XML report (only if module xmlrunner is available)') + parser.add_argument('device_name', help="the device name for device specific tests", + default='', nargs='?') + return parser.parse_args() + def get_test_suite(device_name=''): """ Gets a test suite (collection of test cases) which is relevant for @@ -41,23 +56,23 @@ def get_test_suite(device_name=''): test_suite = unittest.TestSuite(test_suite_list) return test_suite -def run_tests(device_name=''): +def run_tests(device_name='', use_xmlrunner=False): """ Executes the unit tests specified by the test suite. This should be called from CMake. """ test_result = unittest.TestResult() - test_runner = unittest.TextTestRunner(verbosity=2) + if use_xmlrunner and 'XMLTestRunner' in globals(): + test_runner = XMLTestRunner(verbosity=2) + else: + test_runner = unittest.TextTestRunner(verbosity=2) test_result = test_runner.run(get_test_suite(device_name)) return test_result def main(): - if len(sys.argv) >= 2: - mpm_device_name = sys.argv[1] - else: - mpm_device_name = '' + args = parse_args() - if not run_tests(mpm_device_name).wasSuccessful(): + if not run_tests(args.device_name, use_xmlrunner=args.xml).wasSuccessful(): sys.exit(-1) if __name__ == "__main__": |