Known subclasses: testtools.deferredruntest._DeferredRunTest, testtools.tests.helpers.FullStackRunTest, testtools.tests.test_runtest.CustomRunTest

An object to run a test.

RunTest objects are used to implement the internal logic involved in running a test. TestCase.__init__ stores _RunTest as the class of RunTest to execute. Passing the runTest= parameter to TestCase.__init__ allows a different RunTest class to be used to execute the test.

Subclassing or replacing RunTest can be useful to add functionality to the way that tests are run in a given project.

Instance Variable case The test case that is to be run.
Instance Variable result The result object a case is reporting to.
Instance Variable handlers A list of (ExceptionClass, handler_function) for exceptions that should be caught if raised from the user code. Exceptions that are caught are checked against this list in first to last order. There is a catch-all of 'Exception' at the end of the list, so to add a new exception to the list, insert it at the front (which ensures that it will be checked before any existing base classes in the list. If you add multiple exceptions some of which are subclasses of each other, add the most specific exceptions last (so they come before their parent classes in the list).
Instance Variable exception_caught An object returned when _run_user catches an exception.
Method __init__ Create a RunTest to run a case.
Method run Run self.case reporting activity to result.
Instance Variable _exceptions A list of caught exceptions, used to do the single reporting of error/failure/skip etc.
Method _run_one Run one test reporting to result.
Method _run_prepared_result Run one test reporting to result.
Method _run_core Run the user supplied test code.
Method _run_cleanups Run the cleanups that have been added with addCleanup.
Method _run_user Run a user supplied function.
Method _got_user_exception Called when user code raises an exception.
case =
The test case that is to be run.
result =
The result object a case is reporting to.
handlers =
A list of (ExceptionClass, handler_function) for exceptions that should be caught if raised from the user code. Exceptions that are caught are checked against this list in first to last order. There is a catch-all of 'Exception' at the end of the list, so to add a new exception to the list, insert it at the front (which ensures that it will be checked before any existing base classes in the list. If you add multiple exceptions some of which are subclasses of each other, add the most specific exceptions last (so they come before their parent classes in the list).
exception_caught =
An object returned when _run_user catches an exception.
_exceptions =
A list of caught exceptions, used to do the single reporting of error/failure/skip etc.
def __init__(self, case, handlers=None, last_resort=None):
Create a RunTest to run a case.
ParameterscaseA testtools.TestCase test case object.
handlersException handlers for this RunTest. These are stored in self.handlers and can be modified later if needed.
last_resortA handler of last resort: any exception which is not handled by handlers will cause the last resort handler to be called as last_resort(exc_info), and then the exception will be raised - aborting the test run as this is inside the runner machinery rather than the confined context of the test.
def run(self, result=None):
Run self.case reporting activity to result.
ParametersresultOptional testtools.TestResult to report activity to.
ReturnsThe result object the test was run against.
def _run_one(self, result):
Run one test reporting to result.
ParametersresultA testtools.TestResult to report activity to. This result object is decorated with an ExtendedToOriginalDecorator to ensure that the latest TestResult API can be used with confidence by client code.
ReturnsThe result object the test was run against.
def _run_prepared_result(self, result):
Run one test reporting to result.
ParametersresultA testtools.TestResult to report activity to.
ReturnsThe result object the test was run against.
def _run_core(self):
Run the user supplied test code.
def _run_cleanups(self, result):

Run the cleanups that have been added with addCleanup.

See the docstring for addCleanup for more information.

ReturnsNone if all cleanups ran without error, exception_caught if there was an error.
def _run_user(self, fn, *args, **kwargs):

Run a user supplied function.

Exceptions are processed by _got_user_exception.

ReturnsEither whatever 'fn' returns or exception_caught if 'fn' raised an exception.
def _got_user_exception(self, exc_info, tb_label='traceback'):

Called when user code raises an exception.

If 'exc_info' is a MultipleExceptions, then we recurse into it unpacking the errors that it's made up from.

Parametersexc_infoA sys.exc_info() tuple for the user error.
tb_labelAn optional string label for the error. If not specified, will default to 'traceback'.
Returns'exception_caught' if we catch one of the exceptions that have handlers in 'handlers', otherwise raise the error.
API Documentation for testtools, generated by pydoctor at 2015-07-01 16:11:28.