diff options
author | Jordan Moldow <jmoldow@box.com> | 2017-07-29 02:39:17 -0700 |
---|---|---|
committer | Jordan Moldow <jmoldow@box.com> | 2017-07-29 02:39:17 -0700 |
commit | 2e61f702c09899bf375dba0c59eec3760fdd8990 (patch) | |
tree | 0283221fc26d911345186aa423ff67a510a8ecb5 /_pytest/_code/code.py | |
parent | 768edde899fe3629a69d55289f82bb0d95635c06 (diff) | |
download | pytest-2e61f702c09899bf375dba0c59eec3760fdd8990.tar.gz |
Support PEP-415's Exception.__suppress_context__
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 #2631.
Diffstat (limited to '_pytest/_code/code.py')
-rw-r--r-- | _pytest/_code/code.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/_pytest/_code/code.py b/_pytest/_code/code.py index 5750211f2..0230c5660 100644 --- a/_pytest/_code/code.py +++ b/_pytest/_code/code.py @@ -679,7 +679,7 @@ class FormattedExcinfo(object): e = e.__cause__ excinfo = ExceptionInfo((type(e), e, e.__traceback__)) if e.__traceback__ else None descr = 'The above exception was the direct cause of the following exception:' - elif e.__context__ is not None: + elif (e.__context__ is not None and not e.__suppress_context__): e = e.__context__ excinfo = ExceptionInfo((type(e), e, e.__traceback__)) if e.__traceback__ else None descr = 'During handling of the above exception, another exception occurred:' |