MCPcopy Create free account
hub / github.com/zzzeek/sqlalchemy / _assert_proper_exception_context

Function _assert_proper_exception_context

lib/sqlalchemy/testing/assertions.py:372–390  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

370
371
372def _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
393def assert_raises(except_cls, callable_, *args, **kw):

Callers 1

_expect_raisesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected