samba_external: Simplify script to find missing external packages; include subunit...
[samba.git] / lib / testtools / run.py
1 # Copyright (c) 2009 Jonathan M. Lange. See LICENSE for details.
2
3 """python -m testtools.run testspec [testspec...]
4
5 Run some tests with the testtools extended API.
6
7 For instance, to run the testtools test suite.
8  $ python -m testtools.run testtools.tests.test_suite
9 """
10
11 import sys
12
13 from testtools.tests import test_suite
14 from testtools import TextTestResult
15
16
17 class TestToolsTestRunner(object):
18     """ A thunk object to support unittest.TestProgram."""
19
20     def run(self, test):
21         "Run the given test case or test suite."
22         result = TextTestResult(sys.stdout)
23         result.startTestRun()
24         try:
25             return test.run(result)
26         finally:
27             result.stopTestRun()
28
29
30 if __name__ == '__main__':
31     import optparse
32     from unittest import TestProgram
33     parser = optparse.OptionParser(__doc__)
34     args = parser.parse_args()[1]
35     if not args:
36         parser.error("No testspecs given.")
37     runner = TestToolsTestRunner()
38     program = TestProgram(module=None, argv=[sys.argv[0]] + args,
39         testRunner=runner)