Support PEP-415's Exception.__suppress_context__ #2631
Closed
Comments
jmoldow
added a commit
to jmoldow/pytest
that referenced
this issue
Jul 29, 2017
PEP-415 states that `exception.__context__` should be suppressed in traceback outputs, if `exception.__suppress_context__` is `True`. Now if a ``raise exception from None`` is caught by pytest, pytest will no longer chain the context in the test report. The algorithm in `FormattedExcinfo` now better matches the one in `traceback.TracebackException`. `Exception.__suppress_context__` is available in all of the versions of Python 3 that are supported by pytest. Fixes pytest-dev#2631.
Fixed by #2632 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PEP-415 states that
exception.__context__
should be suppressed in traceback outputs, ifexception.__suppress_context__
isTrue
.If a
raise exception from None
is caught by pytest, pytest should not chain the context in the test report.The current algorithm in
_pytest._code.code.FormattedExcinfo
is:which means that pytest always chains the exception, assuming that
e.__context__
hasn't been set toNone
.By comparison, the algorithm in
traceback.TracebackException
is:Exception.__suppress_context__
is available in all of the versions of Python 3 that are supported by pytest, so it is trivial to add support for this feature.Here's a test that has a
raise exception from None
in it: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:
The text was updated successfully, but these errors were encountered: