assert_raises(exception_class, callable, *args, **kwargs) assert_raises(exception_class) Fail unless an exception of class exception_class is thrown by callable when invoked with arguments args and keyword arguments kwargs. If a different type of exception is thrown, it wil
(*args, **kwargs)
| 1506 | |
| 1507 | |
| 1508 | def assert_raises(*args, **kwargs): |
| 1509 | """ |
| 1510 | assert_raises(exception_class, callable, *args, **kwargs) |
| 1511 | assert_raises(exception_class) |
| 1512 | |
| 1513 | Fail unless an exception of class exception_class is thrown |
| 1514 | by callable when invoked with arguments args and keyword |
| 1515 | arguments kwargs. If a different type of exception is |
| 1516 | thrown, it will not be caught, and the test case will be |
| 1517 | deemed to have suffered an error, exactly as for an |
| 1518 | unexpected exception. |
| 1519 | |
| 1520 | Alternatively, `assert_raises` can be used as a context manager: |
| 1521 | |
| 1522 | >>> from numpy.testing import assert_raises |
| 1523 | >>> with assert_raises(ZeroDivisionError): |
| 1524 | ... 1 / 0 |
| 1525 | |
| 1526 | is equivalent to |
| 1527 | |
| 1528 | >>> def div(x, y): |
| 1529 | ... return x / y |
| 1530 | >>> assert_raises(ZeroDivisionError, div, 1, 0) |
| 1531 | |
| 1532 | """ |
| 1533 | __tracebackhide__ = True # Hide traceback for py.test |
| 1534 | return _d.assertRaises(*args, **kwargs) |
| 1535 | |
| 1536 | |
| 1537 | def assert_raises_regex(exception_class, expected_regexp, *args, **kwargs): |
no outgoing calls
searching dependent graphs…