You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Include a detailed description of the bug or suggestion
PEP-415 states that exception.__context__ should be suppressed in traceback outputs, if exception.__suppress_context__ is True.
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:
ife.__cause__isnotNone:
# Code to chain the cause.elife.__context__isnotNone:
# Code to chain the context.
which means that pytest always chains the exception, assuming that e.__context__ hasn't been set to None.
By comparison, the algorithm in traceback.TracebackException is:
ife.__cause__isnotNone:
# Code to chain the cause.elif (e.__context__isnotNoneandnote.__suppress_context__):
# Code to chain the context.
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.
Minimal example if possible
Here's a test that has a raise exception from None in it:
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.
Fixespytest-dev#2631.
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: