testtools.runtest.RunTest(object)
class documentationtesttools.runtest
(View In Hierarchy)
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. |
Parameters | case | A testtools.TestCase test case object. |
handlers | Exception handlers for this RunTest. These are stored in self.handlers and can be modified later if needed. | |
last_resort | A 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. |
Parameters | result | Optional testtools.TestResult to report activity to. |
Returns | The result object the test was run against. |
Parameters | result | A 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. |
Returns | The result object the test was run against. |
Parameters | result | A testtools.TestResult to report activity to. |
Returns | The result object the test was run against. |
Run the cleanups that have been added with addCleanup.
See the docstring for addCleanup for more information.
Returns | None if all cleanups ran without error, exception_caught if there was an error. |
Run a user supplied function.
Exceptions are processed by _got_user_exception
.
Returns | Either whatever 'fn' returns or exception_caught if 'fn' raised an exception. |
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.
Parameters | exc_info | A sys.exc_info() tuple for the user error. |
tb_label | An 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. |