3 # Simple subunit testrunner for python
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
6 # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
7 # license at the users choice. A copy of both licenses are available in the
8 # project source as Apache-2.0 and BSD. You may not use this file except in
9 # compliance with one of these two licences.
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # license you chose for the specific language governing permissions and
15 # limitations under that license.
18 """Run a unittest testcase reporting results as Subunit.
20 $ python -m subunit.run mylib.tests.test_suite
25 from subunit import TestProtocolClient, get_default_formatter
26 from subunit.test_results import AutoTimingTestResultDecorator
27 from testtools.run import (
36 class SubunitTestRunner(object):
37 def __init__(self, stream=sys.stdout):
41 "Run the given test case or test suite."
42 result = TestProtocolClient(self.stream)
43 result = AutoTimingTestResultDecorator(result)
48 class SubunitTestProgram(TestProgram):
52 def usageExit(self, msg=None):
55 usage = {'progName': self.progName, 'catchbreak': '', 'failfast': '',
57 if self.failfast != False:
58 usage['failfast'] = FAILFAST
59 if self.catchbreak != False:
60 usage['catchbreak'] = CATCHBREAK
61 if self.buffer != False:
62 usage['buffer'] = BUFFEROUTPUT
63 usage_text = self.USAGE % usage
64 usage_lines = usage_text.split('\n')
65 usage_lines.insert(2, "Run a test suite with a subunit reporter.")
66 usage_lines.insert(3, "")
67 print('\n'.join(usage_lines))
71 if __name__ == '__main__':
72 stream = get_default_formatter()
73 runner = SubunitTestRunner(stream)
74 SubunitTestProgram(module=None, argv=sys.argv, testRunner=runner,