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

Method assertWarns

Lib/unittest/case.py:823–852  ·  view source on GitHub ↗

Fail unless a warning of class warnClass is triggered by the callable when invoked with specified positional and keyword arguments. If a different type of warning is triggered, it will not be handled: depending on the other warning filtering rules in effe

(self, expected_warning, *args, **kwargs)

Source from the content-addressed store, hash-verified

821 context = None
822
823 def assertWarns(self, expected_warning, *args, **kwargs):
824 """Fail unless a warning of class warnClass is triggered
825 by the callable when invoked with specified positional and
826 keyword arguments. If a different type of warning is
827 triggered, it will not be handled: depending on the other
828 warning filtering rules in effect, it might be silenced, printed
829 out, or raised as an exception.
830
831 If called with the callable and arguments omitted, will return a
832 context object used like this::
833
834 with self.assertWarns(SomeWarning):
835 do_something()
836
837 An optional keyword argument 'msg' can be provided when assertWarns
838 is used as a context object.
839
840 The context manager keeps a reference to the first matching
841 warning as the 'warning' attribute; similarly, the 'filename'
842 and 'lineno' attributes give you information about the line
843 of Python code from which the warning was triggered.
844 This allows you to inspect the warning after the assertion::
845
846 with self.assertWarns(SomeWarning) as cm:
847 do_something()
848 the_warning = cm.warning
849 self.assertEqual(the_warning.some_attribute, 147)
850 """
851 context = _AssertWarnsContext(expected_warning, self)
852 return context.handle('assertWarns', args, kwargs)
853
854 def _assertNotWarns(self, expected_warning, *args, **kwargs):
855 """The opposite of assertWarns. Private due to low demand."""

Calls 2

_AssertWarnsContextClass · 0.85
handleMethod · 0.45