assert that any exception we're catching does not have a __context__ without a __cause__, and that __suppress_context__ is never set. Python 3 will report nested as exceptions as "during the handling of error X, error Y occurred". That's not what we want to do. we want these except
(exception)
| 370 | |
| 371 | |
| 372 | def _assert_proper_exception_context(exception): |
| 373 | """assert that any exception we're catching does not have a __context__ |
| 374 | without a __cause__, and that __suppress_context__ is never set. |
| 375 | |
| 376 | Python 3 will report nested as exceptions as "during the handling of |
| 377 | error X, error Y occurred". That's not what we want to do. we want |
| 378 | these exceptions in a cause chain. |
| 379 | |
| 380 | """ |
| 381 | |
| 382 | if ( |
| 383 | exception.__context__ is not exception.__cause__ |
| 384 | and not exception.__suppress_context__ |
| 385 | ): |
| 386 | assert False, ( |
| 387 | "Exception %r was correctly raised but did not set a cause, " |
| 388 | "within context %r as its cause." |
| 389 | % (exception, exception.__context__) |
| 390 | ) |
| 391 | |
| 392 | |
| 393 | def assert_raises(except_cls, callable_, *args, **kw): |