s4:dsdb/drepl: update the source_dsa_obj/invocation_id in repsFrom
[Samba/gebeck_regimport.git] / lib / testtools / testtools / distutilscmd.py
blob91e14ca504ff25b5ca4eb9062d06b5209abed046
1 # Copyright (c) 2010-2011 testtools developers . See LICENSE for details.
3 """Extensions to the standard Python unittest library."""
5 import sys
7 from distutils.core import Command
8 from distutils.errors import DistutilsOptionError
10 from testtools.run import TestProgram, TestToolsTestRunner
13 class TestCommand(Command):
14 """Command to run unit tests with testtools"""
16 description = "run unit tests with testtools"
18 user_options = [
19 ('catch', 'c', "Catch ctrl-C and display results so far"),
20 ('buffer', 'b', "Buffer stdout and stderr during tests"),
21 ('failfast', 'f', "Stop on first fail or error"),
22 ('test-module=','m', "Run 'test_suite' in specified module"),
23 ('test-suite=','s',
24 "Test suite to run (e.g. 'some_module.test_suite')")
27 def __init__(self, dist):
28 Command.__init__(self, dist)
29 self.runner = TestToolsTestRunner(sys.stdout)
32 def initialize_options(self):
33 self.test_suite = None
34 self.test_module = None
35 self.catch = None
36 self.buffer = None
37 self.failfast = None
39 def finalize_options(self):
40 if self.test_suite is None:
41 if self.test_module is None:
42 raise DistutilsOptionError(
43 "You must specify a module or a suite to run tests from")
44 else:
45 self.test_suite = self.test_module+".test_suite"
46 elif self.test_module:
47 raise DistutilsOptionError(
48 "You may specify a module or a suite, but not both")
49 self.test_args = [self.test_suite]
50 if self.verbose:
51 self.test_args.insert(0, '--verbose')
52 if self.buffer:
53 self.test_args.insert(0, '--buffer')
54 if self.catch:
55 self.test_args.insert(0, '--catch')
56 if self.failfast:
57 self.test_args.insert(0, '--failfast')
59 def run(self):
60 self.program = TestProgram(
61 argv=self.test_args, testRunner=self.runner, stdout=sys.stdout,
62 exit=False)