1 # SPDX-License-Identifier: MIT
3 # Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
6 from tap
import TAPTestRunner
12 if __name__
== "__main__":
13 argparser
= argparse
.ArgumentParser()
14 argparser
.add_argument(
15 "-f", "--failfast", help="Stop on first fail or error", action
="store_true"
18 argparser
.add_argument(
19 "start_dir", help="Base directory where to search for tests", type=str
22 mut_exclu_group
= argparser
.add_mutually_exclusive_group(required
=True)
24 mut_exclu_group
.add_argument(
27 help="Glob-style pattern of test files to run " "(e.g. test_event*.py)",
31 mut_exclu_group
.add_argument(
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)",
40 args
= argparser
.parse_args()
42 loader
= unittest
.TestLoader()
44 start_dir
= args
.start_dir
45 pattern
= args
.pattern
46 failfast
= args
.failfast
47 test_case
= args
.test_case
50 sys
.path
.append(start_dir
)
51 tests
= loader
.loadTestsFromName(test_case
)
53 tests
= loader
.discover(start_dir
, pattern
)
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.
60 if tests
.countTestCases() < 1:
61 print("No tests matching '%s' found in '%s'" % (pattern
, start_dir
))
64 runner
= TAPTestRunner(failfast
=failfast
)
65 runner
.set_stream(True)
66 runner
.set_format("{method_name}")
67 sys
.exit(0 if runner
.run(tests
).wasSuccessful() else 1)
This page took 0.041627 seconds and 4 git commands to generate.