subunit/testtools: Include newer version.
[Samba/eduardoll.git] / lib / subunit / python / subunit / run.py
blob01c0b0e9e6b35911b06db3e3a534769a1cbe41de
1 #!/usr/bin/python
3 # Simple subunit testrunner for python
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
5 #
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
21 """
23 import sys
25 from subunit import TestProtocolClient, get_default_formatter
28 class SubunitTestRunner(object):
29 def __init__(self, stream=sys.stdout):
30 self.stream = stream
32 def run(self, test):
33 "Run the given test case or test suite."
34 result = TestProtocolClient(self.stream)
35 test(result)
36 return result
39 if __name__ == '__main__':
40 import optparse
41 from unittest import TestProgram
42 parser = optparse.OptionParser(__doc__)
43 args = parser.parse_args()[1]
44 stream = get_default_formatter()
45 runner = SubunitTestRunner(stream)
46 program = TestProgram(module=None, argv=[sys.argv[0]] + args,
47 testRunner=runner)