TestCase.assertRaises()
TestCase.assertRaises() is a Python method in the Unittest Module category. Tests that an exception is raised when callable is called. The syntax is TestCase.assertRaises(exception, callable=None, *args, **kwargs). Returns: Context manager. A typical example: with self.assertRaises(ValueError):
int("abc"). A close sibling is unittest.TestCase(), which base class for writing unit tests. Provides assertion methods and test runner support. 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. More about this category: Unit testing framework — TestCase, assertEqual, assertRaises, TestSuite. Related Unittest Module entries: unittest.TestCase(), TestCase.assertEqual(), TestCase.assertTrue(), TestCase.assertFalse(), 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. You can try TestCase.assertRaises() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.