1 # Copyright (c) 2010-2011 testtools developers . See LICENSE for details.
3 """Extensions to the standard Python unittest library."""
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"
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"),
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
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")
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
]
51 self
.test_args
.insert(0, '--verbose')
53 self
.test_args
.insert(0, '--buffer')
55 self
.test_args
.insert(0, '--catch')
57 self
.test_args
.insert(0, '--failfast')
60 self
.program
= TestProgram(
61 argv
=self
.test_args
, testRunner
=self
.runner
, stdout
=sys
.stdout
,