unittest.TestCase()
unittest.TestCase() is a Python function in the Unittest Module category. Base class for writing unit tests. Provides assertion methods and test runner support. The syntax is unittest.TestCase(). Returns: TestCase instance. A typical example: import unittest
class TestMath(unittest.TestCase):
def test_add(self):
self.assertEqual(add(2, 3), 5)
def test_divide(self):
with self.assertRaises(ValueError):
divide(1, 0)
if __name__ == "__main__":
unittest.main(). A close sibling is TestCase.assertEqual(), which tests that first == second. Fails with msg if not equal. A close sibling is TestCase.assertTrue(), which tests that expr is True. A close sibling is TestCase.assertFalse(), which tests that expr is False. A close sibling is TestCase.assertRaises(), which tests that an exception is raised when callable is called. More about this category: Unit testing framework — TestCase, assertEqual, assertRaises, TestSuite. Related Unittest Module entries: TestCase.assertEqual(), TestCase.assertTrue(), TestCase.assertFalse(), TestCase.assertRaises(), TestCase.assertIn(), TestCase.assertIsNone(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.