The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
Asserts that the body of the context manager raises exc.
@contextlib.contextmanager
def raises(
exc: type[Exception] = Exception, # The exception type to check is raised.
contains: str | None = None, # Optionally, check whether the raised exception contains this message.
) -> Generator[ExceptionInfo, None, None]:
"Asserts that the body of the context manager raises `exc`."
raised = True
try:
info = ExceptionInfo()
yield info
raised = False
except exc as e:
info.type_ = type(e)
info.value = e
info.traceback = traceback.format_tb(e.__traceback__)
if contains and contains not in str(e):
raise AssertionError(f"Raised {e} but message does not contain {contains}") from e
if not raised:
raise AssertionError(f"Did not raise {e}")ExceptionInfo(type_=<class 'Exception'>, value=Exception('abc'), traceback=[' File "/tmp/ipykernel_2029/2204637686.py", line 11, in raises\n yield info\n', ' File "/tmp/ipykernel_2029/3922684010.py", line 2, in <module>\n raise Exception("abc")\n'])
Assert that a == b.