pytest-dev / pytest-dev/pytest
Feature request: Add original exception object to pytest_exception_interact
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
I'd really like to have a generic exception handler, maybe via a hook. I use a test application and I'd like to raise custom exception and just catch them in one place like so:
def pytest_exception_handler(item, exc):
if isinstance(exc, KeyError):
pytest.skip('I knew this was gonna happen!)
if isinstance(exc, MyException) and 'foo' in item.name:
raise AnotherGenericException('That foo test is a problem!)
I searched before opening this issue, and couldn't find a way to do this, or even a discussion about this suggestion. If such exist, I apologize.
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
Start by locating the existing pytest_exception_interact hook and reviewing how the exception argument is currently represented. Compare that entry point with the requested generic handler example, then determine what behavior would make the original exception available and how completion could be verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100