From 29cf2c4e8c7e2be6db2d136387ed537ed7c8084b Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Fri, 24 May 2019 01:16:37 +0200 Subject: [PATCH] test: Custom main() function It's not as full featured as unittest.main(), but this will allow us to add custom command line arguments. --- test/composertest.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/composertest.py b/test/composertest.py index 2d1b27dd..86af1a4d 100644 --- a/test/composertest.py +++ b/test/composertest.py @@ -1,5 +1,6 @@ #!/usr/bin/python3 +import argparse import os import subprocess import sys @@ -56,4 +57,17 @@ class ComposerTestCase(unittest.TestCase): def main(): - unittest.main(verbosity=2) + parser = argparse.ArgumentParser() + parser.add_argument("tests", nargs="*", help="List of tests modules, classes, and methods") + args = parser.parse_args() + + module = __import__("__main__") + + if args.tests: + tests = unittest.defaultTestLoader.loadTestsFromNames(args.tests, module) + else: + tests = unittest.defaultTestLoader.loadTestsFromModule(module) + + runner = unittest.TextTestRunner(verbosity=2) + result = runner.run(tests) + sys.exit(not result.wasSuccessful())