From: Simon Marchi Date: Fri, 21 Jun 2019 14:30:11 +0000 (-0400) Subject: test utils: add failfast option to our testrunner.py X-Git-Url: https://git.efficios.com/?a=commitdiff_plain;h=274a82adf9b62f1d4ab764444dfdbf232d7587f5;p=babeltrace.git test utils: add failfast option to our testrunner.py When iterating on a test, I like using the -f|--failfast option of the unittest module. This patch adds the option to pass it to our testrunner. Here's one way to use it (with the babeltrace build dir as the current working directory): tests/utils/test_python_bt2_env python3 /home/smarchi/src/babeltrace/tests/utils/python/testrunner.py /home/smarchi/src/babeltrace/tests/bindings/python/bt2/ -f Note that this is not absolutely essential, it is also possible to call unittest directly: tests/utils/test_python_bt2_env python3 -m unittest discover -s /home/smarchi/src/babeltrace/tests/bindings/python/bt2/ -f However, I prefer using the same runner as what the testsuite uses. To facilitate the handling of optional arguments, I made the script use argparse. Change-Id: Ia4c082dc0952cc8649491b2410ab2d99f1477c1b Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/1528 Tested-by: jenkins Reviewed-by: Francis Deslauriers Reviewed-by: Philippe Proulx --- diff --git a/tests/utils/python/testrunner.py b/tests/utils/python/testrunner.py index 175c8fd1..6a3dbaba 100644 --- a/tests/utils/python/testrunner.py +++ b/tests/utils/python/testrunner.py @@ -23,18 +23,33 @@ from tap import TAPTestRunner import unittest import sys +import argparse 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') + + args = argparser.parse_args() + loader = unittest.TestLoader() - if len(sys.argv) >= 3: - pattern = sys.argv[2] - else: - pattern = 'test*.py' + start_dir = args.start_dir + pattern = args.pattern + failfast = args.failfast - tests = loader.discover(sys.argv[1], pattern) - runner = TAPTestRunner() + tests = loader.discover(start_dir, pattern) + runner = TAPTestRunner(failfast=failfast) runner.set_stream(True) runner.set_format('{method_name}') sys.exit(0 if runner.run(tests).wasSuccessful() else 1)