Remove `skip-string-normalization` in Python formatter config
[babeltrace.git] / tests / utils / python / testrunner.py
CommitLineData
0235b0db 1# SPDX-License-Identifier: MIT
9cf643d1
PP
2#
3# Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
4#
9cf643d1
PP
5
6from tap import TAPTestRunner
7import unittest
8import sys
274a82ad 9import argparse
9cf643d1
PP
10
11
f5567ea8 12if __name__ == "__main__":
274a82ad 13 argparser = argparse.ArgumentParser()
cfbd7cf3 14 argparser.add_argument(
f5567ea8 15 "-f", "--failfast", help="Stop on first fail or error", action="store_true"
cfbd7cf3 16 )
a818a617 17
cfbd7cf3 18 argparser.add_argument(
f5567ea8 19 "start_dir", help="Base directory where to search for tests", type=str
cfbd7cf3 20 )
a818a617
FD
21
22 mut_exclu_group = argparser.add_mutually_exclusive_group(required=True)
23
cfbd7cf3 24 mut_exclu_group.add_argument(
f5567ea8
FD
25 "-p",
26 "--pattern",
27 help="Glob-style pattern of test files to run " "(e.g. test_event*.py)",
cfbd7cf3
FD
28 type=str,
29 )
a818a617 30
cfbd7cf3 31 mut_exclu_group.add_argument(
f5567ea8
FD
32 "-t",
33 "--test-case",
34 help="Run a specfic test module name, test class "
35 "name, or test method name "
36 "(e.g. test_event.EventTestCase.test_clock_value)",
cfbd7cf3
FD
37 type=str,
38 )
274a82ad
SM
39
40 args = argparser.parse_args()
41
9cf643d1 42 loader = unittest.TestLoader()
b83084f5 43
274a82ad
SM
44 start_dir = args.start_dir
45 pattern = args.pattern
46 failfast = args.failfast
a818a617
FD
47 test_case = args.test_case
48
49 if test_case:
50 sys.path.append(start_dir)
51 tests = loader.loadTestsFromName(test_case)
52 elif pattern:
53 tests = loader.discover(start_dir, pattern)
54 else:
55 # This will never happen because the mutual exclusion group has the
56 # `required` parameter set to True. So one or the other must be set or
57 # else it will fail to parse.
58 sys.exit(1)
b83084f5 59
644e0364
MJ
60 if tests.countTestCases() < 1:
61 print("No tests matching '%s' found in '%s'" % (pattern, start_dir))
62 sys.exit(1)
63
274a82ad 64 runner = TAPTestRunner(failfast=failfast)
9cf643d1 65 runner.set_stream(True)
f5567ea8 66 runner.set_format("{method_name}")
9cf643d1 67 sys.exit(0 if runner.run(tests).wasSuccessful() else 1)
This page took 0.064865 seconds and 4 git commands to generate.