-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Add original exception object to pytest_exception_interact #3626
Comments
Can this not be achieved using the hook - |
oh, I apologize, I completely missed that hook. I'll check it out, thanks! |
Well, silly me, this does exactly what I wanted, sorry. You could turn this: def pytest_exception_interact(node, call, report):
if call.excinfo.type is HTTPError and call.excinfo.value.response.status_code == 400:
do_stuff() To this: def pytest_exception_interact(node, call, report, exc):
if isinstace(exc, HTTPError) and exc.response.status_code == 400:
do_stuff() Which is arguably a lot nicer and pythonic. Should I change the issue to reflect that? On a sort of unrelated note, and I apologize if I'm hijacking (my own) issue, is it possible to skip a test that failed during the setup phase? Using |
@liiight perhaps - the hook could be improved, and we'd like to get rid of callinfo in external apis in future ^^ |
I updated the title. I'll leave the description as is for prosperity's sake. |
Ok, started to take a look into this. As I see it there are at least two approaches to this:
def pytest_exception_interact(node, report, exc):
if isinstace(exc, HTTPError) and exc.response.status_code == 400:
do_stuff() The downside here is that it's a breaking change, the upside is that it's the nicest way IMO.
def pytest_exception_interact(node, call, report):
if isinstace(call.exc, HTTPError) and call.exc.response.status_code == 400:
do_stuff() I'm probably missing some broader aspect here though, as I'm not exactly sure where else callinfo is used. |
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:
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.
The text was updated successfully, but these errors were encountered: