unittest.TestCase.assertTrue()

assertTrue(expr, msg=None) assertFalse(expr, msg=None) Test that expr is true (or false). Note that this is equivalent to bool(expr) is True and not to expr is True (use assertIs(expr, True) for the latter). This method should also be avoided when more specific methods are available (e.g. assertEqual(a, b) instead of assertTrue(a == b)), because they provide a better error message in case of failure.

unittest.TestCase.assertSequenceEqual()

assertSequenceEqual(first, second, msg=None, seq_type=None) Tests that two sequences are equal. If a seq_type is supplied, both first and second must be instances of seq_type or a failure will be raised. If the sequences are different an error message is constructed that shows the difference between the two. This method is not called directly by assertEqual(), but it’s used to implement assertListEqual() and assertTupleEqual(). New in version 3.1.

unittest.TestCase.assertSetEqual()

assertSetEqual(first, second, msg=None) Tests that two sets are equal. If not, an error message is constructed that lists the differences between the sets. This method is used by default when comparing sets or frozensets with assertEqual(). Fails if either of first or second does not have a set.difference() method. New in version 3.1.

unittest.TestCase.assertTupleEqual()

assertTupleEqual(first, second, msg=None) Tests that two lists or tuples are equal. If not, an error message is constructed that shows only the differences between the two. An error is also raised if either of the parameters are of the wrong type. These methods are used by default when comparing lists or tuples with assertEqual(). New in version 3.1.

unittest.TestCase.assertNotRegex()

assertNotRegex(text, regex, msg=None) Test that a regex search matches (or does not match) text. In case of failure, the error message will include the pattern and the text (or the pattern and the part of text that unexpectedly matched). regex may be a regular expression object or a string containing a regular expression suitable for use by re.search(). New in version 3.1: under the name assertRegexpMatches. Changed in version 3.2: The method assertRegexpMatches() has been renamed to asse

unittest.TestCase.assertRaisesRegex()

assertRaisesRegex(exception, regex, callable, *args, **kwds) assertRaisesRegex(exception, regex, msg=None) Like assertRaises() but also tests that regex matches on the string representation of the raised exception. regex may be a regular expression object or a string containing a regular expression suitable for use by re.search(). Examples: self.assertRaisesRegex(ValueError, "invalid literal for.*XYZ'$", int, 'XYZ') or: with self.assertRaisesRegex(ValueError, 'literal'

unittest.TestCase.assertRegex()

assertRegex(text, regex, msg=None) assertNotRegex(text, regex, msg=None) Test that a regex search matches (or does not match) text. In case of failure, the error message will include the pattern and the text (or the pattern and the part of text that unexpectedly matched). regex may be a regular expression object or a string containing a regular expression suitable for use by re.search(). New in version 3.1: under the name assertRegexpMatches. Changed in version 3.2: The method assertRegexp

unittest.TestCase.assertRaises()

assertRaises(exception, callable, *args, **kwds) assertRaises(exception, msg=None) Test that an exception is raised when callable is called with any positional or keyword arguments that are also passed to assertRaises(). The test passes if exception is raised, is an error if another exception is raised, or fails if no exception is raised. To catch any of a group of exceptions, a tuple containing the exception classes may be passed as exception. If only the exception and possibly the msg argum

unittest.TestCase.assertNotIsInstance()

assertNotIsInstance(obj, cls, msg=None) Test that obj is (or is not) an instance of cls (which can be a class or a tuple of classes, as supported by isinstance()). To check for the exact type, use assertIs(type(obj), cls). New in version 3.2.

unittest.TestCase.assertNotEqual()

assertNotEqual(first, second, msg=None) Test that first and second are not equal. If the values do compare equal, the test will fail.