Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions
unittest.suite.TestSuite Class Reference
Inheritance diagram for unittest.suite.TestSuite:
Inheritance graph
[legend]
Collaboration diagram for unittest.suite.TestSuite:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def run
def debug
def __repr__
def __eq__
def __ne__
def __iter__
def countTestCases
def addTest
def addTests
def run
def __call__

Public Attributes

_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Member Functions

def _handleClassSetUp
def _get_previous_module
def _handleModuleFixture
def _addClassOrModuleLevelException
def _handleModuleTearDown
def _tearDownPreviousClass

Detailed Description

A test suite is a composite test consisting of a number of TestCases.

For use, create an instance of TestSuite, then add test case instances.
When all tests have been added, the suite can be passed to a test
runner, such as TextTestRunner. It will run the individual test cases
in the order in which they were added, aggregating the results. When
subclassing, do not forget to call the base class constructor.

Definition at line 75 of file suite.py.


Member Function Documentation

def unittest.suite.BaseTestSuite.__call__ (   self,
  args,
  kwds 
) [inherited]

Definition at line 66 of file suite.py.

00066 
00067     def __call__(self, *args, **kwds):
00068         return self.run(*args, **kwds)

def unittest.suite.BaseTestSuite.__eq__ (   self,
  other 
) [inherited]

Definition at line 26 of file suite.py.

00026 
00027     def __eq__(self, other):
00028         if not isinstance(other, self.__class__):
00029             return NotImplemented
00030         return list(self) == list(other)

def unittest.suite.BaseTestSuite.__iter__ (   self) [inherited]

Definition at line 34 of file suite.py.

00034 
00035     def __iter__(self):
00036         return iter(self._tests)

def unittest.suite.BaseTestSuite.__ne__ (   self,
  other 
) [inherited]

Definition at line 31 of file suite.py.

00031 
00032     def __ne__(self, other):
00033         return not self == other

def unittest.suite.BaseTestSuite.__repr__ (   self) [inherited]

Definition at line 23 of file suite.py.

00023 
00024     def __repr__(self):
00025         return "<%s tests=%s>" % (util.strclass(self.__class__), list(self))

def unittest.suite.TestSuite._addClassOrModuleLevelException (   self,
  result,
  exception,
  errorName 
) [private]

Definition at line 190 of file suite.py.

00190 
00191     def _addClassOrModuleLevelException(self, result, exception, errorName):
00192         error = _ErrorHolder(errorName)
00193         addSkip = getattr(result, 'addSkip', None)
00194         if addSkip is not None and isinstance(exception, case.SkipTest):
00195             addSkip(error, str(exception))
00196         else:
00197             result.addError(error, sys.exc_info())

Here is the call graph for this function:

Here is the caller graph for this function:

def unittest.suite.TestSuite._get_previous_module (   self,
  result 
) [private]

Definition at line 154 of file suite.py.

00154 
00155     def _get_previous_module(self, result):
00156         previousModule = None
00157         previousClass = getattr(result, '_previousTestClass', None)
00158         if previousClass is not None:
00159             previousModule = previousClass.__module__
00160         return previousModule
00161 

Here is the call graph for this function:

Here is the caller graph for this function:

def unittest.suite.TestSuite._handleClassSetUp (   self,
  test,
  result 
) [private]

Definition at line 122 of file suite.py.

00122 
00123     def _handleClassSetUp(self, test, result):
00124         previousClass = getattr(result, '_previousTestClass', None)
00125         currentClass = test.__class__
00126         if currentClass == previousClass:
00127             return
00128         if result._moduleSetUpFailed:
00129             return
00130         if getattr(currentClass, "__unittest_skip__", False):
00131             return
00132 
00133         try:
00134             currentClass._classSetupFailed = False
00135         except TypeError:
00136             # test may actually be a function
00137             # so its class will be a builtin-type
00138             pass
00139 
00140         setUpClass = getattr(currentClass, 'setUpClass', None)
00141         if setUpClass is not None:
00142             _call_if_exists(result, '_setupStdout')
00143             try:
00144                 setUpClass()
00145             except Exception as e:
00146                 if isinstance(result, _DebugResult):
00147                     raise
00148                 currentClass._classSetupFailed = True
00149                 className = util.strclass(currentClass)
00150                 errorName = 'setUpClass (%s)' % className
00151                 self._addClassOrModuleLevelException(result, e, errorName)
00152             finally:
00153                 _call_if_exists(result, '_restoreStdout')

Here is the call graph for this function:

Here is the caller graph for this function:

def unittest.suite.TestSuite._handleModuleFixture (   self,
  test,
  result 
) [private]

Definition at line 162 of file suite.py.

00162 
00163     def _handleModuleFixture(self, test, result):
00164         previousModule = self._get_previous_module(result)
00165         currentModule = test.__class__.__module__
00166         if currentModule == previousModule:
00167             return
00168 
00169         self._handleModuleTearDown(result)
00170 
00171 
00172         result._moduleSetUpFailed = False
00173         try:
00174             module = sys.modules[currentModule]
00175         except KeyError:
00176             return
00177         setUpModule = getattr(module, 'setUpModule', None)
00178         if setUpModule is not None:
00179             _call_if_exists(result, '_setupStdout')
00180             try:
00181                 setUpModule()
00182             except Exception as e:
00183                 if isinstance(result, _DebugResult):
00184                     raise
00185                 result._moduleSetUpFailed = True
00186                 errorName = 'setUpModule (%s)' % currentModule
00187                 self._addClassOrModuleLevelException(result, e, errorName)
00188             finally:
00189                 _call_if_exists(result, '_restoreStdout')

Here is the call graph for this function:

Here is the caller graph for this function:

def unittest.suite.TestSuite._handleModuleTearDown (   self,
  result 
) [private]

Definition at line 198 of file suite.py.

00198 
00199     def _handleModuleTearDown(self, result):
00200         previousModule = self._get_previous_module(result)
00201         if previousModule is None:
00202             return
00203         if result._moduleSetUpFailed:
00204             return
00205 
00206         try:
00207             module = sys.modules[previousModule]
00208         except KeyError:
00209             return
00210 
00211         tearDownModule = getattr(module, 'tearDownModule', None)
00212         if tearDownModule is not None:
00213             _call_if_exists(result, '_setupStdout')
00214             try:
00215                 tearDownModule()
00216             except Exception as e:
00217                 if isinstance(result, _DebugResult):
00218                     raise
00219                 errorName = 'tearDownModule (%s)' % previousModule
00220                 self._addClassOrModuleLevelException(result, e, errorName)
00221             finally:
00222                 _call_if_exists(result, '_restoreStdout')

Here is the call graph for this function:

Here is the caller graph for this function:

def unittest.suite.TestSuite._tearDownPreviousClass (   self,
  test,
  result 
) [private]

Definition at line 223 of file suite.py.

00223 
00224     def _tearDownPreviousClass(self, test, result):
00225         previousClass = getattr(result, '_previousTestClass', None)
00226         currentClass = test.__class__
00227         if currentClass == previousClass:
00228             return
00229         if getattr(previousClass, '_classSetupFailed', False):
00230             return
00231         if getattr(result, '_moduleSetUpFailed', False):
00232             return
00233         if getattr(previousClass, "__unittest_skip__", False):
00234             return
00235 
00236         tearDownClass = getattr(previousClass, 'tearDownClass', None)
00237         if tearDownClass is not None:
00238             _call_if_exists(result, '_setupStdout')
00239             try:
00240                 tearDownClass()
00241             except Exception as e:
00242                 if isinstance(result, _DebugResult):
00243                     raise
00244                 className = util.strclass(previousClass)
00245                 errorName = 'tearDownClass (%s)' % className
00246                 self._addClassOrModuleLevelException(result, e, errorName)
00247             finally:
00248                 _call_if_exists(result, '_restoreStdout')
00249 

Here is the call graph for this function:

Here is the caller graph for this function:

def unittest.suite.BaseTestSuite.addTest (   self,
  test 
) [inherited]

Definition at line 43 of file suite.py.

00043 
00044     def addTest(self, test):
00045         # sanity checks
00046         if not hasattr(test, '__call__'):
00047             raise TypeError("{} is not callable".format(repr(test)))
00048         if isinstance(test, type) and issubclass(test,
00049                                                  (case.TestCase, TestSuite)):
00050             raise TypeError("TestCases and TestSuites must be instantiated "
00051                             "before passing them to addTest()")
00052         self._tests.append(test)

Here is the caller graph for this function:

def unittest.suite.BaseTestSuite.addTests (   self,
  tests 
) [inherited]

Definition at line 53 of file suite.py.

00053 
00054     def addTests(self, tests):
00055         if isinstance(tests, str):
00056             raise TypeError("tests must be an iterable of tests, not a string")
00057         for test in tests:
00058             self.addTest(test)

Here is the call graph for this function:

def unittest.suite.BaseTestSuite.countTestCases (   self) [inherited]

Definition at line 37 of file suite.py.

00037 
00038     def countTestCases(self):
00039         cases = 0
00040         for test in self:
00041             cases += test.countTestCases()
00042         return cases

Run the tests without collecting errors in a TestResult

Reimplemented from unittest.suite.BaseTestSuite.

Definition at line 115 of file suite.py.

00115 
00116     def debug(self):
00117         """Run the tests without collecting errors in a TestResult"""
00118         debug = _DebugResult()
00119         self.run(debug, True)

def unittest.suite.BaseTestSuite.run (   self,
  result 
) [inherited]

Definition at line 59 of file suite.py.

00059 
00060     def run(self, result):
00061         for test in self:
00062             if result.shouldStop:
00063                 break
00064             test(result)
00065         return result

Here is the caller graph for this function:

def unittest.suite.TestSuite.run (   self,
  result,
  debug = False 
)

Definition at line 85 of file suite.py.

00085 
00086     def run(self, result, debug=False):
00087         topLevel = False
00088         if getattr(result, '_testRunEntered', False) is False:
00089             result._testRunEntered = topLevel = True
00090 
00091         for test in self:
00092             if result.shouldStop:
00093                 break
00094 
00095             if _isnotsuite(test):
00096                 self._tearDownPreviousClass(test, result)
00097                 self._handleModuleFixture(test, result)
00098                 self._handleClassSetUp(test, result)
00099                 result._previousTestClass = test.__class__
00100 
00101                 if (getattr(test.__class__, '_classSetupFailed', False) or
00102                     getattr(result, '_moduleSetUpFailed', False)):
00103                     continue
00104 
00105             if not debug:
00106                 test(result)
00107             else:
00108                 test.debug()
00109 
00110         if topLevel:
00111             self._tearDownPreviousClass(None, result)
00112             self._handleModuleTearDown(result)
00113             result._testRunEntered = False
00114         return result

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.


The documentation for this class was generated from the following file: