Instances of the TestCase class represent the logical test units in the unittest universe. This class is intended to be used as a base class, with specific tests being implemented by concrete subclasses. This class implements the interface needed by the test runner to allow it to drive the tests, and methods that the test code can use to check for and report various kinds of failure.
class unittest.TestCase(methodName='runTest')
@classmethod
def setUpClass(cls):
...
@classmethod
def tearDownClass(cls):
...
with self.assertRaises(SomeException):
do_something()
with self.assertRaises(SomeException) as cm:
do_something()
the_exception = cm.exception
self.assertEqual(the_exception.error_code, 3)
self.assertRaisesRegex(ValueError, "invalid literal for.*XYZ'$",
int, 'XYZ')