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
{{ message }}
Repository navigation
ExceptionInfo.for_later() wont add assertion strip text #12175
Using exc_info.exconly(tryshort=True) is meant to remove AssertionError: from the exception message according to (ref)
When 'tryshort' resolves to True, and the exception is an AssertionError, only the actual exception part of the exception representation is returned (so 'AssertionError: ' is removed from the beginning).
However, this is not the case. In addition, the tests do not assert this behaviour:
changed the title [-]Incorrect behaviour of ``ExceptionInfo.exconly()``[/-][+]``ExceptionInfo.for_later()`` wont add assertion strip text[/+]on Apr 2, 2024
Activity
RonnyPfannschmidt commentedon Apr 2, 2024
pytest/src/_pytest/_code/code.py
Line 503 in 4489528
[-]Incorrect behaviour of ``ExceptionInfo.exconly()``[/-][+]``ExceptionInfo.for_later()`` wont add assertion strip text[/+]RonnyPfannschmidt commentedon Apr 2, 2024
the root cause is the for_later helper for making a instance before the exception
we never fill in the strip text for that case
if you create a new exception info object from the value of the one captured the new instance would behave correct
picnixz commentedon Apr 4, 2024
By the way, here is the current workaround I am using in Sphinx (probably imperfect but suitable for my needs):
Fix ExceptionInfo.for_later() not populating _striptext
Derive ExceptionInfo strip text lazily from the exception