Vscode-python: VSCode automatically catches errors when using pytest to debug python scripts.

Created on 1 Sep 2020  路  8Comments  路  Source: microsoft/vscode-python


Because in VSCode, pytest test only gives test results. (Success or failure).

Is it possible to let VSCode automatically catch errors when using pytest to debug python scripts, just like regular debugging python scripts, automatically jump to the line of code with errors.

I tried to set breakpoints for it. Although it can stop and enter the code, it cannot be automatically captured. For projects with a large amount of code, setting breakpoints is too much work.

https://raw.githubusercontent.com/jill123-cc/11/master/debug.PNG

area-debugging type-enhancement

Most helpful comment

We're planning to address this issue in question in a more straightforward way by adding support for user uncaught exceptions, as mentioned by Karthik. We'll likely start by experimenting with some parts of the functionality before we ship it (https://github.com/microsoft/vscode-python/issues/14312).

All 8 comments

Thank you for the suggestion! We have marked this issue as "needs decision" to make sure we have a conversation about your idea. We plan to leave this feature request open for at least a month to see how many 馃憤 votes the opening comment gets to help us make our decision.

@karthiknadig Thank you very much for your reply!

@karthiknadig Thank you also from my side, as I raised this in https://stackoverflow.com/questions/63619498/vs-code-python-debugging-pytest-test-with-the-debugger and @jill123-cc was kind enough to clarify it and raise it as an issue here.

But perhaps this should rather be an issue for pytest - to provide a mode that would stop its processing at the point of error, similarly to what Python's _unittest_ does when called by .debug() [Ref] . With that, you'd fall automatically into the debugger - something which doesn't seem to be possible with pytest.

@mcgfeller @jill123-cc Just to add, the debugger use in the extension (debugpy), supports a mode where any exception crossing the user-code to library boundary would cause a break (exception breakpoint). Essentially the exception is treated as "un-handled by user". The implementation of it had some complications (you can see the discussion here https://github.com/microsoft/debugpy/issues/275).

This comment in pytest might be helpful with using the current exception mechanism to break on assertion error. https://github.com/pytest-dev/pytest/issues/7409#issuecomment-648972170

The recipe actually solves my problem. I wish it would be more straightforward, either in debugpy or in pytest. Much thanks to @jill123-cc and @karthiknadig for helping and pointing me in the right direction. Highly appreciated!

@mcgfeller You're welcome! And thank you for sharing this method!

We're planning to address this issue in question in a more straightforward way by adding support for user uncaught exceptions, as mentioned by Karthik. We'll likely start by experimenting with some parts of the functionality before we ship it (https://github.com/microsoft/vscode-python/issues/14312).

Thank you @luabud . Looking forward to the feature.

Was this page helpful?
0 / 5 - 0 ratings