Skip to content

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

Closed

Description

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...

Activity

  1. int19h commented on Apr 9, 2020

    @int19h
    Contributor

    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.

    Fabio Zadrozny (@fabioz), does this sound feasible?

  2. int19h commented on Apr 9, 2020

    @int19h
    Contributor

    Nikolaus Waxweiler (@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.

  3. changed the title [-]Debug Test: Launch debugger automatically on uncaught exception[/-] [+]Break debugger on exceptions that aren't handled inside a pytest test[/+] on Apr 9, 2020
  4. fabioz commented on Apr 9, 2020

    @fabioz
    Collaborator

    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 Pavel Minaev (@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?

  5. karthiknadig commented on Apr 9, 2020

    @karthiknadig
    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

  6. fabioz commented on Apr 9, 2020

    @fabioz
    Collaborator

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

  7. karthiknadig commented on Apr 10, 2020

    @karthiknadig
    Member
  8. jekbradbury commented on May 19, 2020

    @jekbradbury

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

  9. fabioz commented on May 19, 2020

    @fabioz
    Collaborator

    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).

  10. fabioz commented on May 27, 2020

    @fabioz
    Collaborator

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

  11. added 4 commits that reference this issue on May 28, 2020
    a53ea0f
    ebe5603
    1372293
    6b74e82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions