MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / assertRaises

Method assertRaises

tools/python-3.11.9-amd64/Lib/unittest/case.py:738–769  ·  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 suf

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

Source from the content-addressed store, hash-verified

736 return '%s : %s' % (safe_repr(standardMsg), safe_repr(msg))
737
738 def assertRaises(self, expected_exception, *args, **kwargs):
739 """Fail unless an exception of class expected_exception is raised
740 by the callable when invoked with specified positional and
741 keyword arguments. If a different type of exception is
742 raised, it will not be caught, and the test case will be
743 deemed to have suffered an error, exactly as for an
744 unexpected exception.
745
746 If called with the callable and arguments omitted, will return a
747 context object used like this::
748
749 with self.assertRaises(SomeException):
750 do_something()
751
752 An optional keyword argument 'msg' can be provided when assertRaises
753 is used as a context object.
754
755 The context manager keeps a reference to the exception as
756 the 'exception' attribute. This allows you to inspect the
757 exception after the assertion::
758
759 with self.assertRaises(SomeException) as cm:
760 do_something()
761 the_exception = cm.exception
762 self.assertEqual(the_exception.error_code, 3)
763 """
764 context = _AssertRaisesContext(expected_exception, self)
765 try:
766 return context.handle('assertRaises', args, kwargs)
767 finally:
768 # bpo-23890: manually break a reference cycle
769 context = None
770
771 def assertWarns(self, expected_warning, *args, **kwargs):
772 """Fail unless a warning of class warnClass is triggered

Callers 15

test_simpleMethod · 0.95
test_chararrayMethod · 0.95
test_structMethod · 0.95
checkInvalidParamMethod · 0.80
_test_widgetMethod · 0.80
test_place_forgetMethod · 0.80
test_place_infoMethod · 0.80
test_place_slavesMethod · 0.80
test_grid_anchorMethod · 0.80

Calls 2

handleMethod · 0.45

Tested by 15

test_simpleMethod · 0.76
test_chararrayMethod · 0.76
test_structMethod · 0.76
checkInvalidParamMethod · 0.64
test_place_forgetMethod · 0.64
test_place_infoMethod · 0.64
test_place_slavesMethod · 0.64
test_grid_anchorMethod · 0.64
test_grid_bboxMethod · 0.64