Remove `skip-string-normalization` in Python formatter config
[babeltrace.git] / tests / utils / python / testrunner.py
index cb1bdcda3e16f177c0faf744496acb63f78a323f..a7cd82639adaef00e62c96d4aabfd572dc3b5d13 100644 (file)
@@ -1,24 +1,7 @@
-# The MIT License (MIT)
+# SPDX-License-Identifier: MIT
 #
 # Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
 #
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
 
 from tap import TAPTestRunner
 import unittest
@@ -26,19 +9,33 @@ import sys
 import argparse
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     argparser = argparse.ArgumentParser()
-    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')
+    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
+    )
+
+    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()
 
@@ -47,8 +44,18 @@ if __name__ == '__main__':
     start_dir = args.start_dir
     pattern = args.pattern
     failfast = args.failfast
+    test_case = args.test_case
 
-    tests = loader.discover(start_dir, pattern)
+    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)
 
     if tests.countTestCases() < 1:
         print("No tests matching '%s' found in '%s'" % (pattern, start_dir))
@@ -56,5 +63,5 @@ if __name__ == '__main__':
 
     runner = TAPTestRunner(failfast=failfast)
     runner.set_stream(True)
-    runner.set_format('{method_name}')
+    runner.set_format("{method_name}")
     sys.exit(0 if runner.run(tests).wasSuccessful() else 1)
This page took 0.026082 seconds and 4 git commands to generate.