7 class TestSuite(object):
8 """A test suite is a composite test consisting of a number of TestCases.
10 For use, create an instance of TestSuite, then add test case instances.
11 When all tests have been added, the suite can be passed to a test
12 runner, such as TextTestRunner. It will run the individual test cases
13 in the order in which they were added, aggregating the results. When
14 subclassing, do not forget to call the base class constructor.
16 def __init__(self
, tests
=()):
21 return "<%s tests=%s>" % (util
.strclass(self
.__class
__), list(self
))
23 def __eq__(self
, other
):
24 if not isinstance(other
, self
.__class
__):
26 return list(self
) == list(other
)
28 def __ne__(self
, other
):
29 return not self
== other
31 # Can't guarantee hash invariant, so flag as unhashable
35 return iter(self
._tests
)
37 def countTestCases(self
):
40 cases
+= test
.countTestCases()
43 def addTest(self
, test
):
45 if not hasattr(test
, '__call__'):
46 raise TypeError("the test to add must be callable")
47 if isinstance(test
, type) and issubclass(test
,
48 (case
.TestCase
, TestSuite
)):
49 raise TypeError("TestCases and TestSuites must be instantiated "
50 "before passing them to addTest()")
51 self
._tests
.append(test
)
53 def addTests(self
, tests
):
54 if isinstance(tests
, basestring
):
55 raise TypeError("tests must be an iterable of tests, not a string")
59 def run(self
, result
):
66 def __call__(self
, *args
, **kwds
):
67 return self
.run(*args
, **kwds
)
70 """Run the tests without collecting errors in a TestResult"""