argparser.add_argument('-f', '--failfast',
help='Stop on first fail or error',
action='store_true')
+
argparser.add_argument('start_dir',
help='Base directory where to search for tests',
type=str)
- argparser.add_argument('pattern',
- help='Glob-style pattern of tests to run',
- type=str,
- nargs='?',
- default='test*.py')
+
+ mut_exclu_group = argparser.add_mutually_exclusive_group(required=True)
+
+ mut_exclu_group.add_argument('-p', '--pattern',
+ help='Glob-style pattern of test files to run '
+ '(e.g. test_event*.py)',
+ type=str)
+
+ mut_exclu_group.add_argument('-t', '--test-case',
+ help='Run a specfic test module name, test class '
+ 'name, or test method name '
+ '(e.g. test_event.EventTestCase.test_clock_value)',
+ type=str)
+
args = argparser.parse_args()
start_dir = args.start_dir
pattern = args.pattern
failfast = args.failfast
+ test_case = args.test_case
+
+ if test_case:
+ sys.path.append(start_dir)
+ tests = loader.loadTestsFromName(test_case)
+ elif pattern:
+ tests = loader.discover(start_dir, pattern)
+ else:
+ # This will never happen because the mutual exclusion group has the
+ # `required` parameter set to True. So one or the other must be set or
+ # else it will fail to parse.
+ sys.exit(1)
- tests = loader.discover(start_dir, pattern)
if tests.countTestCases() < 1:
print("No tests matching '%s' found in '%s'" % (pattern, start_dir))
# $2 : The pattern to match python test script names (optional)
run_python_bt2_test() {
local test_dir="$1"
- local test_pattern="${2:-}" # optional
+ local test_pattern="${2:-'*'}" # optional, if none default to "*"
local ret
local test_runner_args=()
run_python_bt2 \
"${python_exec}" \
"${BT_TESTS_SRCDIR}/utils/python/testrunner.py" \
- "${test_runner_args[@]}"
+ --pattern "$test_pattern" \
+ "$test_dir" \
+
ret=$?
if test "x${BT_TESTS_COVERAGE_REPORT:-}" = "x1"; then