class unittest.TestSuite(tests=())
This class represents an aggregation of individual tests cases and test suites. The class presents the interface needed by the test runner to allow it to be run as any other test case. Running a TestSuite
instance is the same as iterating over the suite, running each test individually.
If tests is given, it must be an iterable of individual test cases or other test suites that will be used to build the suite initially. Additional methods are provided to add test cases and suites to the collection later on.
TestSuite
objects behave much like TestCase
objects, except they do not actually implement a test. Instead, they are used to aggregate tests into groups of tests that should be run together. Some additional methods are available to add tests to TestSuite
instances:
-
addTest(test)
-
Add a
TestCase
orTestSuite
to the suite.
-
addTests(tests)
-
Add all the tests from an iterable of
TestCase
andTestSuite
instances to this test suite.This is equivalent to iterating over tests, calling
addTest()
for each element.
TestSuite
shares the following methods with TestCase
:
-
run(result)
-
Run the tests associated with this suite, collecting the result into the test result object passed as result. Note that unlike
TestCase.run()
,TestSuite.run()
requires the result object to be passed in.
-
debug()
-
Run the tests associated with this suite without collecting the result. This allows exceptions raised by the test to be propagated to the caller and can be used to support running tests under a debugger.
-
countTestCases()
-
Return the number of tests represented by this test object, including all individual tests and sub-suites.
-
__iter__()
-
Tests grouped by a
TestSuite
are always accessed by iteration. Subclasses can lazily provide tests by overriding__iter__()
. Note that this method may be called several times on a single suite (for example when counting tests or comparing for equality) so the tests returned by repeated iterations beforeTestSuite.run()
must be the same for each call iteration. AfterTestSuite.run()
, callers should not rely on the tests returned by this method unless the caller uses a subclass that overridesTestSuite._removeTestAtIndex()
to preserve test references.Changed in version 3.2: In earlier versions the
TestSuite
accessed tests directly rather than through iteration, so overriding__iter__()
wasn’t sufficient for providing tests.Changed in version 3.4: In earlier versions the
TestSuite
held references to eachTestCase
afterTestSuite.run()
. Subclasses can restore that behavior by overridingTestSuite._removeTestAtIndex()
.
In the typical usage of a TestSuite
object, the run()
method is invoked by a TestRunner
rather than by the end-user test harness.
Please login to continue.