mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
- Move assert_raises to testutils - Add optional message argument, with reasonable default - Reverse order of expr and exception type for readability - Lambda argument no longer takes parameter - Convert applicable snippets to use assert_raises
21 lines
489 B
Python
21 lines
489 B
Python
def assert_raises(exc_type, expr, msg=None):
|
|
"""
|
|
Helper function to assert `expr` raises an exception of type `exc_type`.
|
|
Args:
|
|
expr: Callable
|
|
exec_type: Exception
|
|
Returns:
|
|
None
|
|
Raises:
|
|
Assertion error on failure
|
|
"""
|
|
try:
|
|
expr()
|
|
except exc_type:
|
|
pass
|
|
else:
|
|
failmsg = f'{exc_type.__name__} was not raised'
|
|
if msg is not None:
|
|
failmsg += f': {msg}'
|
|
assert False, failmsg
|