pytest-dev / pytest-dev/pytest
``ExceptionInfo.for_later()`` wont add assertion strip text
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
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:
MWE
cat <<-EOF > excinfo_exconly.py
import pytest
def test():
with pytest.raises(AssertionError) as exc_info:
raise AssertionError('message')
assert exc_info.exconly(tryshort=True) == 'message'
EOF
pytest excinfo_exconly.py
Environment
Platform: linux; (Linux-5.14.21-150500.55.52-default-x86_64-with-glibc2.31)
Python version: 3.10.13 (main, Sep 05 2023, 11:46:10) [GCC])
Python implementation: CPython
Pytest version: 8.0.2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the MWE with pytest, then inspect testing/code/test_excinfo.py around lines 332-339 and the ExceptionInfo.for_later()/exconly() behavior. Add coverage for an AssertionError with tryshort=True, and confirm the result is "message" without the "AssertionError: " prefix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100