summaryrefslogtreecommitdiff
path: root/testing/framework/TestUnit/cli.py
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2019-07-24 09:57:09 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2019-07-24 09:57:09 +0200
commitc7665433b2004d2b404d6fb9d6fd064998486f63 (patch)
tree8525ef6d24f7c6ceb238945ebb2cc997c7afc905 /testing/framework/TestUnit/cli.py
parente48d2727885efda8369c7edbc2e3929a59532adc (diff)
parent6e228c305122f0564eda1e67d56651f8386d24d7 (diff)
Merge branch 'release/debian/3.1.0+repack-1'debian/3.1.0+repack-1
Diffstat (limited to 'testing/framework/TestUnit/cli.py')
-rw-r--r--testing/framework/TestUnit/cli.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/testing/framework/TestUnit/cli.py b/testing/framework/TestUnit/cli.py
new file mode 100644
index 0000000..6aec735
--- /dev/null
+++ b/testing/framework/TestUnit/cli.py
@@ -0,0 +1,35 @@
+"""
+Choose test runner class from --runner command line option
+and execute test cases.
+"""
+
+import unittest
+import optparse
+import sys
+
+
+def get_runner():
+ parser = optparse.OptionParser()
+ parser.add_option('--runner', default='unittest.TextTestRunner',
+ help='name of test runner class to use')
+ opts, args = parser.parse_args()
+
+ fromsplit = opts.runner.rsplit('.', 1)
+ if len(fromsplit) < 2:
+ raise ValueError('Can\'t use module as a runner')
+ else:
+ runnermod = __import__(fromsplit[0])
+ return getattr(runnermod, fromsplit[1])
+
+
+def run(suite=None):
+ runner = get_runner()
+ if suite:
+ if not runner().run(suite).wasSuccessful():
+ sys.exit(1)
+ else:
+ unittest.main(argv=sys.argv[:1], testRunner=runner)
+
+
+if __name__ == '__main__':
+ run()