Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Support PEP-415's Exception.__suppress_context__ #2631
PEP-415 states that
The current algorithm in
if e.__cause__ is not None: # Code to chain the cause. elif e.__context__ is not None: # Code to chain the context.
which means that pytest always chains the exception, assuming that
By comparison, the algorithm in
if e.__cause__ is not None: # Code to chain the cause. elif (e.__context__ is not None and not e.__suppress_context__): # Code to chain the context.
Here's a test that has a
def test_raise_from_none(): try: raise ValueError() except Exception: raise AttributeError() from None
This is the test output (with the chained exception traceback) that results when running against the pytest feature branch (commit 768edde):
But running the same code in a terminal produces this shorter, non-chained traceback:
And this is what the pytest output should look like: