Known subclasses: twisted.trial.unittest.SynchronousTestCase

Replaces many of the built-in TestCase assertions. In general, these assertions provide better error messages and are easier to use in callbacks.

Method fail Absolutely fail the test. Do not pass go, do not collect $200.
Method assertFalse Fail the test if condition evaluates to True.
Method assertTrue Fail the test if condition evaluates to False.
Method assertRaises Fail the test unless calling the function f with the given args and kwargs raises exception. The failure will report the traceback and call stack of the unexpected exception.
Method assertEqual Fail the test if first and second are not equal.
Method assertIs Fail the test if first is not second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test.
Method assertIsNot Fail the test if first is second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test.
Method assertNotEqual Fail the test if first == second.
Method assertIn Fail the test if containee is not found in container.
Method assertNotIn Fail the test if containee is found in container.
Method assertNotAlmostEqual Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero.
Method assertAlmostEqual Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero.
Method assertApproximates Fail if first - second > tolerance
Method assertSubstring Fail if substring does not exist within astring.
Method assertNotSubstring Fail if astring contains substring.
Method assertWarns Fail if the given function doesn't generate the specified warning when called. It calls the function, checks the warning, and forwards the result of the function if everything is fine.
Method assertIsInstance Fail if instance is not an instance of the given class or of one of the given classes.
Method assertNotIsInstance Fail if instance is an instance of the given class or of one of the given classes.
Method successResultOf Return the current success result of deferred or raise self.failureException.
Method failureResultOf Return the current failure result of deferred or raise self.failureException.
Method assertNoResult Assert that deferred does not have a result at this point.
Method assertRegex Fail the test if a regexp search of text fails.
def fail(self, msg=None):

Absolutely fail the test. Do not pass go, do not collect $200.

Parametersmsgthe message that will be displayed as the reason for the failure
def assertFalse(self, condition, msg=None):

Fail the test if condition evaluates to True.

Parametersconditionany object that defines __nonzero__
def assertTrue(self, condition, msg=None):

Fail the test if condition evaluates to False.

Parametersconditionany object that defines __nonzero__
def assertRaises(self, exception, *args, f=None, **kwargs):

Fail the test unless calling the function f with the given args and kwargs raises exception. The failure will report the traceback and call stack of the unexpected exception.

Parametersexceptionexception type that is to be expected
fthe function to call
ReturnsIf f is None, a context manager which will make an assertion about the exception raised from the suite it manages. If f is not None, the exception raised by f.
Raisesself.failureExceptionRaised if the function call does not raise an exception or if it raises an exception of a different type.
def assertEqual(self, first, second, msg=None):

Fail the test if first and second are not equal.

ParametersmsgA string describing the failure that's included in the exception.
def assertIs(self, first, second, msg=None):

Fail the test if first is not second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test.

Parametersmsgif msg is None, then the failure message will be '%r is not %r' % (first, second)
def assertIsNot(self, first, second, msg=None):

Fail the test if first is second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test.

Parametersmsgif msg is None, then the failure message will be '%r is %r' % (first, second)
def assertNotEqual(self, first, second, msg=None):

Fail the test if first == second.

Parametersmsgif msg is None, then the failure message will be '%r == %r' % (first, second)
def assertIn(self, containee, container, msg=None):

Fail the test if containee is not found in container.

Parameterscontaineethe value that should be in container
containera sequence type, or in the case of a mapping type, will follow semantics of 'if key in dict.keys()'
msgif msg is None, then the failure message will be '%r not in %r' % (first, second)
def assertNotIn(self, containee, container, msg=None):

Fail the test if containee is found in container.

Parameterscontaineethe value that should not be in container
containera sequence type, or in the case of a mapping type, will follow semantics of 'if key in dict.keys()'
msgif msg is None, then the failure message will be '%r in %r' % (first, second)
def assertNotAlmostEqual(self, first, second, places=7, msg=None):

Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero.

Notesdecimal places (from zero) is usually not the same as significant digits (measured from the most significant digit).
included for compatibility with PyUnit test cases
def assertAlmostEqual(self, first, second, places=7, msg=None):

Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero.

Notesdecimal places (from zero) is usually not the same as significant digits (measured from the most significant digit).
included for compatibility with PyUnit test cases
def assertApproximates(self, first, second, tolerance, msg=None):

Fail if first - second > tolerance

Parametersmsgif msg is None, then the failure message will be '%r ~== %r' % (first, second)
def assertSubstring(self, substring, astring, msg=None):

Fail if substring does not exist within astring.

def assertNotSubstring(self, substring, astring, msg=None):

Fail if astring contains substring.

def assertWarns(self, category, message, filename, f, *args, **kwargs):

Fail if the given function doesn't generate the specified warning when called. It calls the function, checks the warning, and forwards the result of the function if everything is fine.

Parameterscategorythe category of the warning to check.
messagethe output message of the warning to check.
filenamethe filename where the warning should come from.
fthe function which is supposed to generate the warning. (type: any callable.)
argsthe arguments to f.
kwargsthe keywords arguments to f.
Returnsthe result of the original function f.
def assertIsInstance(self, instance, classOrTuple, message=None):

Fail if instance is not an instance of the given class or of one of the given classes.

Parametersinstancethe object to test the type (first argument of the isinstance call). (type: any.)
classOrTuplethe class or classes to test against (second argument of the isinstance call). (type: class, type, or tuple.)
messageCustom text to include in the exception text if the assertion fails.
def assertNotIsInstance(self, instance, classOrTuple):

Fail if instance is an instance of the given class or of one of the given classes.

Parametersinstancethe object to test the type (first argument of the isinstance call). (type: any.)
classOrTuplethe class or classes to test against (second argument of the isinstance call). (type: class, type, or tuple.)
def successResultOf(self, deferred):

Return the current success result of deferred or raise self.failureException.

ParametersdeferredA Deferred which has a success result. This means Deferred.callback or Deferred.errback has been called on it and it has reached the end of its callback chain and the last callback or errback returned a non-failure.Failure. (type: Deferred)
ReturnsThe result of deferred.
RaisesSynchronousTestCase.failureExceptionIf the Deferred has no result or has a failure result.
def failureResultOf(self, deferred, *expectedExceptionTypes):

Return the current failure result of deferred or raise self.failureException.

ParametersdeferredA Deferred which has a failure result. This means Deferred.callback or Deferred.errback has been called on it and it has reached the end of its callback chain and the last callback or errback raised an exception or returned a failure.Failure. (type: Deferred)
expectedExceptionTypesException types to expect - if provided, and the exception wrapped by the failure result is not one of the types provided, then this test will fail.
ReturnsThe failure result of deferred. (type: failure.Failure)
RaisesSynchronousTestCase.failureExceptionIf the Deferred has no result, has a success result, or has an unexpected failure result.
def assertNoResult(self, deferred):

Assert that deferred does not have a result at this point.

If the assertion succeeds, then the result of deferred is left unchanged. Otherwise, any failure.Failure result is swallowed.

ParametersdeferredA Deferred without a result. This means that neither Deferred.callback nor Deferred.errback has been called, or that the Deferred is waiting on another Deferred for a result. (type: Deferred)
RaisesSynchronousTestCase.failureExceptionIf the Deferred has a result.
def assertRegex(self, text, regex, msg=None):

Fail the test if a regexp search of text fails.

ParameterstextText which is under test. (type: str)
regexA regular expression object or a string containing a regular expression suitable for use by re.search(). (type: str or re.RegexObject)
msgText used as the error message on failure. (type: str)
API Documentation for twisted, generated by pydoctor at 2020-03-25 17:34:30.