Known subclasses: testtools.tests.matchers.test_basic.DoesNotEndWithTests, testtools.tests.matchers.test_basic.DoesNotStartWithTests, testtools.tests.matchers.test_basic.EndsWithTests, testtools.tests.matchers.test_basic.StartsWithTests, testtools.tests.matchers.test_basic.Test_BinaryMismatch, testtools.tests.matchers.test_basic.TestContainsInterface, testtools.tests.matchers.test_basic.TestEqualsInterface, testtools.tests.matchers.test_basic.TestGreaterThanInterface, testtools.tests.matchers.test_basic.TestHasLength, testtools.tests.matchers.test_basic.TestIsInstanceInterface, testtools.tests.matchers.test_basic.TestIsInterface, testtools.tests.matchers.test_basic.TestLessThanInterface, testtools.tests.matchers.test_basic.TestMatchesRegex, testtools.tests.matchers.test_basic.TestNotEqualsInterface, testtools.tests.matchers.test_basic.TestSameMembers, testtools.tests.matchers.test_datastructures.TestContainsAllInterface, testtools.tests.matchers.test_datastructures.TestMatchesListwise, testtools.tests.matchers.test_datastructures.TestMatchesSetwise, testtools.tests.matchers.test_datastructures.TestMatchesStructure, testtools.tests.matchers.test_dict.TestContainedByDict, testtools.tests.matchers.test_dict.TestContainsDict, testtools.tests.matchers.test_dict.TestKeysEqualWithList, testtools.tests.matchers.test_dict.TestMatchesAllDictInterface, testtools.tests.matchers.test_dict.TestMatchesDict, testtools.tests.matchers.test_dict.TestSubDictOf, testtools.tests.matchers.test_doctest.TestDocTestMatchesInterface, testtools.tests.matchers.test_doctest.TestDocTestMatchesInterfaceUnicode, testtools.tests.matchers.test_doctest.TestDocTestMatchesSpecific, testtools.tests.matchers.test_exception.TestMatchesExceptionInstanceInterface, testtools.tests.matchers.test_exception.TestMatchesExceptionTypeInterface, testtools.tests.matchers.test_exception.TestMatchesExceptionTypeMatcherInterface, testtools.tests.matchers.test_exception.TestMatchesExceptionTypeReInterface, testtools.tests.matchers.test_exception.TestRaisesBaseTypes, testtools.tests.matchers.test_exception.TestRaisesConvenience, testtools.tests.matchers.test_exception.TestRaisesExceptionMatcherInterface, testtools.tests.matchers.test_exception.TestRaisesInterface, testtools.tests.matchers.test_filesystem.TestDirContains, testtools.tests.matchers.test_filesystem.TestDirExists, testtools.tests.matchers.test_filesystem.TestFileContains, testtools.tests.matchers.test_filesystem.TestFileExists, testtools.tests.matchers.test_filesystem.TestHasPermissions, testtools.tests.matchers.test_filesystem.TestPathExists, testtools.tests.matchers.test_filesystem.TestSamePath, testtools.tests.matchers.test_filesystem.TestTarballContains, testtools.tests.matchers.test_higherorder.TestAfterPreprocessing, testtools.tests.matchers.test_higherorder.TestAllMatch, testtools.tests.matchers.test_higherorder.TestAnnotate, testtools.tests.matchers.test_higherorder.TestAnnotatedMismatch, testtools.tests.matchers.test_higherorder.TestAnyMatch, testtools.tests.matchers.test_higherorder.TestMatchersAnyInterface, testtools.tests.matchers.test_higherorder.TestMatchesAllInterface, testtools.tests.matchers.test_higherorder.TestMatchesPredicate, testtools.tests.matchers.test_higherorder.TestMatchesPredicateWithParams, testtools.tests.matchers.test_higherorder.TestNotInterface, testtools.tests.matchers.test_impl.TestMismatch, testtools.tests.matchers.test_impl.TestMismatchDecorator, testtools.tests.matchers.test_impl.TestMismatchError, testtools.tests.test_assert_that.TestAssertThatFunction, testtools.tests.test_assert_that.TestAssertThatMethod, testtools.tests.test_compat.TestReraise, testtools.tests.test_compat.TestTextRepr, testtools.tests.test_compat.TestUnicodeOutputStream, testtools.tests.test_content.TestAttachFile, testtools.tests.test_content.TestContent, testtools.tests.test_content.TestStackLinesContent, testtools.tests.test_content.TestStacktraceContent, testtools.tests.test_content.TestTracebackContent, testtools.tests.test_content_type.TestBuiltinContentTypes, testtools.tests.test_content_type.TestContentType, testtools.tests.test_deferredruntest.X.Base, testtools.tests.test_distutilscmd.TestCommandTest, testtools.tests.test_fixturesupport.TestFixtureSupport, testtools.tests.test_helpers.TestStackHiding, testtools.tests.test_monkey.MonkeyPatcherTest, testtools.tests.test_monkey.TestPatchHelper, testtools.tests.test_run.TestRun, testtools.tests.test_runtest.TestRunTest, testtools.tests.test_runtest.TestTestCaseSupportForRunTest, testtools.tests.test_spinner.NeedsTwistedTestCase, testtools.tests.test_tags.TestTags, testtools.tests.test_testcase.Attributes, testtools.tests.test_testcase.TestAddCleanup, testtools.tests.test_testcase.TestAddCleanup.LoggingTest, testtools.tests.test_testcase.TestAssertions, testtools.tests.test_testcase.TestAttributes, testtools.tests.test_testcase.TestCloneTestWithNewId, testtools.tests.test_testcase.TestDecorateTestCaseResult, testtools.tests.test_testcase.TestEquality, testtools.tests.test_testcase.TestErrorHolder, testtools.tests.test_testcase.TestNullary, testtools.tests.test_testcase.TestOnException, testtools.tests.test_testcase.TestPatchSupport, testtools.tests.test_testcase.TestPatchSupport.Case, testtools.tests.test_testcase.TestPlaceHolder, testtools.tests.test_testcase.TestRunTestUsage, testtools.tests.test_testcase.TestSetupTearDown, testtools.tests.test_testcase.TestSkipping, testtools.tests.test_testcase.TestTestCaseSuper, testtools.tests.test_testcase.TestUniqueFactories, testtools.tests.test_testcase.TestWithDetails, testtools.tests.test_testresult.TestAdaptedPython26TestResultContract, testtools.tests.test_testresult.TestAdaptedPython27TestResultContract, testtools.tests.test_testresult.TestAdaptedStreamResult, testtools.tests.test_testresult.TestBaseStreamResultContract, testtools.tests.test_testresult.TestByTestResultTests, testtools.tests.test_testresult.TestCopyStreamResultContract, testtools.tests.test_testresult.TestCopyStreamResultCopies, testtools.tests.test_testresult.TestDetailsToStr, testtools.tests.test_testresult.TestDoubleStreamResultContract, testtools.tests.test_testresult.TestDoubleStreamResultEvents, testtools.tests.test_testresult.TestExtendedTestResultContract, testtools.tests.test_testresult.TestExtendedToOriginalResultDecoratorBase, testtools.tests.test_testresult.TestExtendedToStreamDecorator, testtools.tests.test_testresult.TestExtendedToStreamDecoratorContract, testtools.tests.test_testresult.TestMergeTags, testtools.tests.test_testresult.TestMultiTestResult, testtools.tests.test_testresult.TestMultiTestResultContract, testtools.tests.test_testresult.TestNonAsciiResults, testtools.tests.test_testresult.TestPython26TestResultContract, testtools.tests.test_testresult.TestPython27TestResultContract, testtools.tests.test_testresult.TestStreamFailFast, testtools.tests.test_testresult.TestStreamFailFastContract, testtools.tests.test_testresult.TestStreamResultRouter, testtools.tests.test_testresult.TestStreamResultRouterContract, testtools.tests.test_testresult.TestStreamSummary, testtools.tests.test_testresult.TestStreamSummaryResultContract, testtools.tests.test_testresult.TestStreamTagger, testtools.tests.test_testresult.TestStreamTaggerContract, testtools.tests.test_testresult.TestStreamToDict, testtools.tests.test_testresult.TestStreamToDictContract, testtools.tests.test_testresult.TestStreamToExtendedContract, testtools.tests.test_testresult.TestStreamToExtendedDecoratorContract, testtools.tests.test_testresult.TestStreamToQueue, testtools.tests.test_testresult.TestStreamToQueueContract, testtools.tests.test_testresult.TestTagger, testtools.tests.test_testresult.TestTestControl, testtools.tests.test_testresult.TestTestResult, testtools.tests.test_testresult.TestTestResultContract, testtools.tests.test_testresult.TestTestResultDecoratorContract, testtools.tests.test_testresult.TestTextTestResult, testtools.tests.test_testresult.TestTextTestResultContract, testtools.tests.test_testresult.TestThreadSafeForwardingResult, testtools.tests.test_testresult.TestThreadSafeForwardingResultContract, testtools.tests.test_testresult.TestTimestampingStreamResult, testtools.tests.test_testsuite.Sample, testtools.tests.test_testsuite.TestConcurrentStreamTestSuiteRun, testtools.tests.test_testsuite.TestConcurrentTestSuiteRun, testtools.tests.test_testsuite.TestFixtureSuite, testtools.tests.test_testsuite.TestSortedTests, testtools.tests.test_with_with.TestExpectedException

Extensions to the basic TestCase.
Instance Variable exception_handlers Exceptions to catch from setUp, runTest and tearDown. This list is able to be modified at any time and consists of (exception_class, handler(case, result, exception_value)) pairs.
Instance Variable force_failure Force testtools.RunTest to fail the test after the test has completed.
Class Variable run_tests_with A factory to make the RunTest to run tests with. Defaults to RunTest. The factory is expected to take a test case and an optional list of exception handlers.
Method __init__ Construct a TestCase.
Method __eq__ Undocumented
Method __repr__ Undocumented
Method addDetail Add a detail to be reported with this test's outcome.
Method getDetails Get the details dict that will be reported with this test's outcome.
Method patch Monkey-patch 'obj.attribute' to 'value' while the test is running.
Method shortDescription Undocumented
Method skipTest Cause this test to be skipped.
Method addCleanup Add a cleanup function to be called after tearDown.
Method addOnException Add a handler to be called when an exception occurs in test code.
Method assertEqual Assert that 'expected' is equal to 'observed'.
Method assertIn Assert that needle is in haystack.
Method assertIsNone Assert that 'observed' is equal to None.
Method assertIsNotNone Assert that 'observed' is not equal to None.
Method assertIs Assert that 'expected' is 'observed'.
Method assertIsNot Assert that 'expected' is not 'observed'.
Method assertNotIn Assert that needle is not in haystack.
Method assertIsInstance Undocumented
Method assertRaises No summary
Method assertThat Assert that matchee is matched by matcher.
Method addDetailUniqueName Add a detail to the test, but ensure it's name is unique.
Method expectThat Check that matchee is matched by matcher, but delay the assertion failure.
Method defaultTestResult Undocumented
Method expectFailure Check that a test fails in a particular way.
Method getUniqueInteger Get an integer unique to this test.
Method getUniqueString Get a string unique to this test.
Method onException Called when an exception propogates from test code.
Method run Undocumented
Method useFixture Use fixture in a test case.
Method setUp Undocumented
Method tearDown Undocumented
Method _formatTypes Format a class or a bunch of classes for display in an error.
Method _add_reason Undocumented
Method _matchHelper Undocumented
Static Method _report_error Undocumented
Static Method _report_expected_failure Undocumented
Static Method _report_failure Undocumented
Static Method _report_skip Undocumented
Method _report_traceback Undocumented
Static Method _report_unexpected_success Undocumented
Method _run_setup Run the setUp function for this test.
Method _run_teardown Run the tearDown function for this test.
Method _get_test_method Undocumented
Method _run_test_method Run the test method for this test.
exception_handlers =
Exceptions to catch from setUp, runTest and tearDown. This list is able to be modified at any time and consists of (exception_class, handler(case, result, exception_value)) pairs.
force_failure =
Force testtools.RunTest to fail the test after the test has completed.
run_tests_with =
A factory to make the RunTest to run tests with. Defaults to RunTest. The factory is expected to take a test case and an optional list of exception handlers.
def __init__(self, *args, **kwargs):
Construct a TestCase.
ParameterstestMethodThe name of the method to run.
runTestOptional class to use to execute the test. If not supplied RunTest is used. The instance to be used is created when run() is invoked, so will be fresh each time. Overrides TestCase.run_tests_with if given.
def __eq__(self, other):
Undocumented
def __repr__(self):
Undocumented
def addDetail(self, name, content_object):

Add a detail to be reported with this test's outcome.

For more details see pydoc testtools.TestResult.

ParametersnameThe name to give this detail.
content_objectThe content object for this detail. See testtools.content for more detail.
def getDetails(self):

Get the details dict that will be reported with this test's outcome.

For more details see pydoc testtools.TestResult.

def patch(self, obj, attribute, value):

Monkey-patch 'obj.attribute' to 'value' while the test is running.

If 'obj' has no attribute, then the monkey-patch will still go ahead, and the attribute will be deleted instead of restored to its original value.

ParametersobjThe object to patch. Can be anything.
attributeThe attribute on 'obj' to patch.
valueThe value to set 'obj.attribute' to.
def shortDescription(self):
Undocumented
def skipTest(self, reason):

Cause this test to be skipped.

This raises self.skipException(reason). skipException is raised to permit a skip to be triggered at any point (during setUp or the testMethod itself). The run() method catches skipException and translates that into a call to the result objects addSkip method.

ParametersreasonThe reason why the test is being skipped. This must support being cast into a unicode string for reporting.
def _formatTypes(self, classOrIterable):
Format a class or a bunch of classes for display in an error.
def addCleanup(self, function, *arguments, **keywordArguments):

Add a cleanup function to be called after tearDown.

Functions added with addCleanup will be called in reverse order of adding after tearDown, or after setUp if setUp raises an exception.

If a function added with addCleanup raises an exception, the error will be recorded as a test error, and the next cleanup will then be run.

Cleanup functions are always called before a test finishes running, even if setUp is aborted by an exception.

def addOnException(self, handler):

Add a handler to be called when an exception occurs in test code.

This handler cannot affect what result methods are called, and is called before any outcome is called on the result object. An example use for it is to add some diagnostic state to the test details dict which is expensive to calculate and not interesting for reporting in the success case.

Handlers are called before the outcome (such as addFailure) that the exception has caused.

Handlers are called in first-added, first-called order, and if they raise an exception, that will propogate out of the test running machinery, halting test processing. As a result, do not call code that may unreasonably fail.

def _add_reason(self, reason):
Undocumented
def assertEqual(self, expected, observed, message=''):
Assert that 'expected' is equal to 'observed'.
ParametersexpectedThe expected value.
observedThe observed value.
messageAn optional message to include in the error.
def assertIn(self, needle, haystack, message=''):
Assert that needle is in haystack.
def assertIsNone(self, observed, message=''):
Assert that 'observed' is equal to None.
ParametersobservedThe observed value.
messageAn optional message describing the error.
def assertIsNotNone(self, observed, message=''):
Assert that 'observed' is not equal to None.
ParametersobservedThe observed value.
messageAn optional message describing the error.
def assertIs(self, expected, observed, message=''):
Assert that 'expected' is 'observed'.
ParametersexpectedThe expected value.
observedThe observed value.
messageAn optional message describing the error.
def assertIsNot(self, expected, observed, message=''):
Assert that 'expected' is not 'observed'.
def assertNotIn(self, needle, haystack, message=''):
Assert that needle is not in haystack.
def assertIsInstance(self, obj, klass, msg=None):
Undocumented
def assertRaises(self, excClass, callableObj, *args, **kwargs):
Fail unless an exception of class excClass is thrown by callableObj when invoked with arguments args and keyword arguments kwargs. If a different type of exception is thrown, it will not be caught, and the test case will be deemed to have suffered an error, exactly as for an unexpected exception.
def assertThat(self, matchee, matcher, message='', verbose=False):
Assert that matchee is matched by matcher.
ParametersmatcheeAn object to match with matcher.
matcherAn object meeting the testtools.Matcher protocol.
RaisesMismatchErrorWhen matcher does not match thing.
def addDetailUniqueName(self, name, content_object):

Add a detail to the test, but ensure it's name is unique.

This method checks whether name conflicts with a detail that has already been added to the test. If it does, it will modify name to avoid the conflict.

For more details see pydoc testtools.TestResult.

ParametersnameThe name to give this detail.
content_objectThe content object for this detail. See testtools.content for more detail.
def expectThat(self, matchee, matcher, message='', verbose=False):

Check that matchee is matched by matcher, but delay the assertion failure.

This method behaves similarly to assertThat, except that a failed match does not exit the test immediately. The rest of the test code will continue to run, and the test will be marked as failing after the test has finished.

ParametersmatcheeAn object to match with matcher.
matcherAn object meeting the testtools.Matcher protocol.
messageIf specified, show this message with any failed match.
def _matchHelper(self, matchee, matcher, message, verbose):
Undocumented
def defaultTestResult(self):
Undocumented
def expectFailure(self, reason, predicate, *args, **kwargs):

Check that a test fails in a particular way.

If the test fails in the expected way, a KnownFailure is caused. If it succeeds an UnexpectedSuccess is caused.

The expected use of expectFailure is as a barrier at the point in a test where the test would fail. For example: >>> def test_foo(self): >>> self.expectFailure("1 should be 0", self.assertNotEqual, 1, 0) >>> self.assertEqual(1, 0)

If in the future 1 were to equal 0, the expectFailure call can simply be removed. This separation preserves the original intent of the test while it is in the expectFailure mode.

def getUniqueInteger(self):

Get an integer unique to this test.

Returns an integer that is guaranteed to be unique to this instance. Use this when you need an arbitrary integer in your test, or as a helper for custom anonymous factory methods.

def getUniqueString(self, prefix=None):

Get a string unique to this test.

Returns a string that is guaranteed to be unique to this instance. Use this when you need an arbitrary string in your test, or as a helper for custom anonymous factory methods.

ParametersprefixThe prefix of the string. If not provided, defaults to the id of the tests.
ReturnsA bytestring of '<prefix>-<unique_int>'.
def onException(self, exc_info, tb_label='traceback'):
Called when an exception propogates from test code.
See Also
@staticmethod
def _report_error(self, result, err):
Undocumented
@staticmethod
def _report_expected_failure(self, result, err):
Undocumented
@staticmethod
def _report_failure(self, result, err):
Undocumented
@staticmethod
def _report_skip(self, result, err):
Undocumented
def _report_traceback(self, exc_info, tb_label='traceback'):
Undocumented
@staticmethod
def _report_unexpected_success(self, result, err):
Undocumented
def run(self, result=None):
Undocumented
def _run_setup(self, result):
Run the setUp function for this test.
ParametersresultA testtools.TestResult to report activity to.
RaisesValueErrorIf the base class setUp is not called, a ValueError is raised.
def _run_teardown(self, result):
Run the tearDown function for this test.
ParametersresultA testtools.TestResult to report activity to.
RaisesValueErrorIf the base class tearDown is not called, a ValueError is raised.
def _get_test_method(self):
Undocumented
def _run_test_method(self, result):
Run the test method for this test.
ParametersresultA testtools.TestResult to report activity to.
ReturnsNone.
def useFixture(self, fixture):

Use fixture in a test case.

The fixture will be setUp, and self.addCleanup(fixture.cleanUp) called.

ParametersfixtureThe fixture to use.
ReturnsThe fixture, after setting it up and scheduling a cleanup for it.
API Documentation for testtools, generated by pydoctor at 2015-07-01 16:11:28.