-
Notifications
You must be signed in to change notification settings - Fork 137
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
Debugging tests is not stopping on breakpoint #1175
Comments
Does it break if you manually call |
No, it doesn't - not in VS Code, at least. If I run |
This implies that the debugger doesn't get attached at all. By chance, are you using |
No - just plain
|
Can you try enabling logging via |
@int19h I don't have that directory. This is what I see in my home directory with those sort of filenames: |
I'm not finding anything called |
It should be under Can you check that Alternatively, just set the environment variable |
A config with You could also try changing the config to invoke pytest directly via "program" and "args", and use F5 to run it instead of Test Explorer - although it might not reproduce then (but that would also be useful to know to diagnose it properly). |
Sorry for replying late,
|
@Aisuko, in your case I think the reason is that your check has an extra underscore in it in this line, after "main": if __name__ == "__main___": thus the line with the breakpoint simply never runs. |
Oh, thank you. It is the main reason in my case. Sorry for bringing up a confusing case. |
This issue was closed because it has been stalled for 30 days with no activity. If the issue still persists, please reopen with the information requested. Thanks. |
I'm also encountering the problem of breakpoint not being respected when debugging tests |
In my case, I had tried everything without success. I then just upgraded my Pytest version (to 7.3.1), and it worked. |
I was in the same situation, and what was even more strange was that in the same tests directory, some file breakpoints worked and some did not. After I upgraded pytest (from 7.4.3 to 8.0.0), the breakpoints all worked. |
@int19h - You said:
How is this "template" configured? Or did you just mean that it is the magic that hooks it to the "Debug test" debugger launch? I have unit tests that are testing endpoints in a python application running in another process, and I want "Debug test" to attach to this process so I can debug the endpoint implementation when my tests hit them. However, vscode will not let me configure How are people debugging API endpoint implementations with vscode without this? I've been spiraling on this and can't find a solution. Note that I have this running in the API server so I can attach, but it isn't helping for "Debug test": import debugpy
debugpy.listen(5678) For anyone else landing here, the current docs on |
Run Tests needs to be in charge of launching the test runner process so it can do all the things that it needs to do - like say enumerating tests - hence why setting the purpose means you can't specify "program" etc (because the program would be the test runner). However, the tests themselves can of course spawn child processes of their own, in whatever way you need to test them. So for an API endpoint implemented in Flask, I'd expect a test fixture somewhere that actually spins up the app. |
Fixturing should definitely start the server (or at least ensure it is running). However, what I'm trying to figure out is how to debug an attached process (or even a subprocess) during a "Debug test" run of a unit test. I am unable to find a functional permutation of vscode options to let me debug subprocess (or attached) code. I'm wondering if I should make a distinct issue for this, since this one is only marginally on topic. I've also made a test project with a basic echo server to test it out on, and show possible/impossible/failed permutations: |
Normally I'd expect setting A separate issue would be best, and you might want to file it directly on https://github.com/microsoft/vscode-python/ since that's where the logic that maps high-level test configs to underlying debugpy configs lives. |
I posted the issue I was discussing above, with example, to the vscode-python-debugger project here: |
Type: Bug
Behaviour
Expected vs. Actual
Expected: setting a breakpoint on a test and then debugging the test should trigger the breakpoint to enable step-by-step execution of the test.
Actual: the test just runs through. The debugger panel appears at the top of the window but the debugger never stops execution of the code.
Steps to reproduce:
Diagnostic data
python.languageServer
setting: PylanceOutput for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)User Settings
Extension version: 2022.20.2
VS Code version: Code - Insiders 1.75.0-insider (6d40104789d03d41b8866a1e57847dae14c5cf0d, 2023-01-12T05:34:21.597Z)
OS version: Windows_NT x64 10.0.22621
Modes:
Sandboxed: Yes
Remote OS version: Linux x64 5.15.79.1-microsoft-standard-WSL2
System Info
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
A/B Experiments
The text was updated successfully, but these errors were encountered: