Skip to content
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

Break debugger on exceptions that aren't handled inside a pytest test #111

Closed
madig opened this issue Apr 9, 2020 · 9 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@madig
Copy link

madig commented Apr 9, 2020

When running "Debug Test" from the code edit view, the test output pane shows me pytest's error message when it encounters an uncaught exception, but I would like it to launch a debugger instead. I currently have to insert a try/catch with a breakpoint() otherwise.

I actually feel this should have been requested already but could find neither an issue nor a setting for this...

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Apr 9, 2020
@int19h
Copy link
Contributor

int19h commented Apr 9, 2020

The problem here is that we're not treating the exception is uncaught. I think this is because it's caught by pytest.

However, pytest is library code, not user code; and we run with "justMyCode": true by default. Thus, if the exception escapes to library code with no possibility that it might flow back into user code, we should consider it as unhandled. For example, we can walk the stack and see if there are any frames below pytest that are user code.

@fabioz, does this sound feasible?

@int19h int19h added the bug Something isn't working label Apr 9, 2020
@int19h
Copy link
Contributor

int19h commented Apr 9, 2020

@madig As a partial workaround, you can try checking "Raised exceptions" in the Breakpoints pane. The downside is that it'll also report exceptions that you throw and then handle in your code.

@fabioz fabioz changed the title Debug Test: Launch debugger automatically on uncaught exception Break debugger on exceptions that aren't handled inside a pytest test Apr 9, 2020
@fabioz
Copy link
Collaborator

fabioz commented Apr 9, 2020

I've renamed from my understanding of the request (please correct it if I understood wrong).

Well, the problem is that technically this isn't an uncaught exception (because as @int19h mentioned, it's caught by pytest)...

I don't think it's feasible to report it as uncaught before actually being uncaught (this isn't the actual semantic of uncaught exceptions and breaking it makes the handling quite tricky)... maybe it'd be possible to have a test unhandled exception which reports if the exception is raised when a test method exists?

@karthiknadig
Copy link
Member

There is userUnhandled mode when setting extension breakpoints. I think we could make use of it instead. VS 2017/2019 supports this, and for VSC we could also provide it as an additional checkbox. Currently we translate userUnhandled to unhandled for VS.
https://microsoft.github.io/debug-adapter-protocol/specification#Types_ExceptionBreakMode

@fabioz
Copy link
Collaborator

fabioz commented Apr 9, 2020

Ok, I'll try to come up with a proper implementation for userUnhandled as it seems like it'd solve this use case.

@fabioz fabioz self-assigned this Apr 9, 2020
@karthiknadig
Copy link
Member

/cc @rchiodo

@jekbradbury
Copy link

Any updates? I find myself wanting this functionality just about every day... 🙂

@fabioz
Copy link
Collaborator

fabioz commented May 19, 2020

Not yet (I have 2 other issues in the queue before getting this one, so, I'd say I'll probably get to it in a couple of weeks).

@fabioz
Copy link
Collaborator

fabioz commented May 27, 2020

Note: I'm starting to take a look at this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants