-
Notifications
You must be signed in to change notification settings - Fork 174
Description
Environment data
- VS Code version: 1.53.2
- Extension version (available under the Extensions sidebar): v2021.2.582707922
- OS and version: MacOS 11.2.1 (Big Sur)
- Python version (& distribution if applicable, e.g. Anaconda): 3.8.5 (Conda)
- Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
- Value of the
python.languageServer
setting: Pylance
Expected behaviour
I am running some tests using python's unittest. When an exception is raised, I'd like VS Code to breakpoint at the point the error is thrown. I have "Uncaught Exceptions" enabled and "Raised Exceptions" disabled, and I see the desired behaviour when running the code normally (not with unittest). In the minimum working example below, I'd like the code to breakpoint at line 4 when the exception is raised.
Actual behaviour
Instead of the desried/expected behaviour, the breakpoint is on the final line with an empty stack call and no way of getting back to line 4 or the variables present at that time. This makes debugging useless. I imagine this occurs because unittest catches all uncaught exceptions, so I'd like a way for VSCode to breakpoint if the except
was not written by the user (as is the case with unittest). I've seen a suggested solution here (microsoft/vscode-python#14056 (comment)) and also thought that setting justMyCode
might help, too, but neither did.
Caveat 1: I know I could enable "Raised Exceptions" but the code I'm working on has lots of intentional raises which are caught. So enabling "Raised Exceptions" would take too long to sift through all the intentional raises.
Caveat 2: I know there is the "Test" tab. When I click to debug the test it says "No Tests Ran". This is strange because I simply run the test from inside the "Test" tab, it successfully runs (it still raises the error, and there is no breakpointing, but it runs at least).
Steps to reproduce:
In the example below, I'd like the breakpoint at line 4 (raise RuntimeError()
), but I'm getting it instead at line 11 (unittest.main()
), which has an empty stack call and no way to get back to line 4 or any of the variables that were present at that time.
import unittest
def something():
raise RuntimeError()
class TestClass(unittest.TestCase):
def test_method(self):
something()
if __name__ == "__main__":
unittest.main()