test(main.py): add cli option to select test suite (#4023)

This commit is contained in:
some00
2023-03-02 09:51:55 +01:00
committed by GitHub
parent c4f993a245
commit 7854d55046

View File

@@ -90,7 +90,7 @@ def build_tests(options_name, build_type, clean):
'--parallel', str(os.cpu_count())]) '--parallel', str(os.cpu_count())])
def run_tests(options_name): def run_tests(options_name, test_suite):
'''Run the tests for the given options name.''' '''Run the tests for the given options name.'''
print() print()
@@ -101,8 +101,15 @@ def run_tests(options_name):
print('=' * len(label), flush=True) print('=' * len(label), flush=True)
os.chdir(get_build_dir(options_name)) os.chdir(get_build_dir(options_name))
subprocess.check_call( args = [
['ctest', '--timeout', '300', '--parallel', str(os.cpu_count()), '--output-on-failure']) 'ctest',
'--timeout', '300',
'--parallel', str(os.cpu_count()),
'--output-on-failure',
]
if test_suite is not None:
args.extend(["--tests-regex", test_suite])
subprocess.check_call(args)
def generate_code_coverage_report(): def generate_code_coverage_report():
@@ -151,6 +158,8 @@ if __name__ == "__main__":
help='generate code coverage report for tests.') help='generate code coverage report for tests.')
parser.add_argument('actions', nargs='*', choices=['build', 'test'], parser.add_argument('actions', nargs='*', choices=['build', 'test'],
help='build: compile build tests, test: compile/run executable tests.') help='build: compile build tests, test: compile/run executable tests.')
parser.add_argument('--test-suite', default=None,
help='select test suite to run')
args = parser.parse_args() args = parser.parse_args()
@@ -171,7 +180,7 @@ if __name__ == "__main__":
build_tests(options_name, build_type, args.clean) build_tests(options_name, build_type, args.clean)
if is_test: if is_test:
try: try:
run_tests(options_name) run_tests(options_name, args.test_suite)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
sys.exit(e.returncode) sys.exit(e.returncode)