MCPcopy Index your code
hub / github.com/RustPython/RustPython / assertRaises

Method assertRaises

Lib/unittest/case.py:790–821  ·  view source on GitHub ↗

Fail unless an exception of class expected_exception is raised by the callable when invoked with specified positional and keyword arguments. If a different type of exception is raised, it will not be caught, and the test case will be deemed to have suffere

(self, expected_exception, *args, **kwargs)

Source from the content-addressed store, hash-verified

788 return '%s : %s' % (safe_repr(standardMsg), safe_repr(msg))
789
790 def assertRaises(self, expected_exception, *args, **kwargs):
791 """Fail unless an exception of class expected_exception is raised
792 by the callable when invoked with specified positional and
793 keyword arguments. If a different type of exception is
794 raised, it will not be caught, and the test case will be
795 deemed to have suffered an error, exactly as for an
796 unexpected exception.
797
798 If called with the callable and arguments omitted, will return a
799 context object used like this::
800
801 with self.assertRaises(SomeException):
802 do_something()
803
804 An optional keyword argument 'msg' can be provided when assertRaises
805 is used as a context object.
806
807 The context manager keeps a reference to the exception as
808 the 'exception' attribute. This allows you to inspect the
809 exception after the assertion::
810
811 with self.assertRaises(SomeException) as cm:
812 do_something()
813 the_exception = cm.exception
814 self.assertEqual(the_exception.error_code, 3)
815 """
816 context = _AssertRaisesContext(expected_exception, self)
817 try:
818 return context.handle('assertRaises', args, kwargs)
819 finally:
820 # bpo-23890: manually break a reference cycle
821 context = None
822
823 def assertWarns(self, expected_warning, *args, **kwargs):
824 """Fail unless a warning of class warnClass is triggered

Calls 2

handleMethod · 0.45