microsoft / debugpy

An implementation of the Debug Adapter Protocol for Python
https://pypi.org/project/debugpy/
Other
1.85k stars 137 forks source link

Debugging tests is not stopping on breakpoint #1175

Closed pcolmer closed 1 year ago

pcolmer commented 1 year ago

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:

  1. Right-click on the green run button in the test file's gutter.
  2. Click "Add breakpoint". Green run button turns red.
  3. Right-click and choose "Debug Test".

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

``` Experiment 'pythonSurveyNotification' is active Experiment 'pythonPromptNewToolsExt' is active LSP Notebooks experiment is enabled LSP Notebooks interactive window support is enabled Python interpreter path: ~/.local/share/virtualenvs/sd-webhook-framework-zRqUmWf2/bin/python Starting Pylance language server. > . ~/.local/share/virtualenvs/sd-webhook-framework-zRqUmWf2/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/printEnvVariables.py > ~/.local/share/virtualenvs/sd-webhook-framework-zRqUmWf2/bin/python ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear tests cwd: . > conda info --json [ERROR 2023-0-13 10:3:12.74]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/cdk-static-websites-AZV3rDYY doesn't contain a valid path to the project > . ~/.local/share/virtualenvs/sd-webhook-framework-zRqUmWf2/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/printEnvVariables.py > ~/.pyenv/versions/2.7.18/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py [ERROR 2023-0-13 10:3:12.169]: [Error: Command failed: /home/philip/.pyenv/versions/2.7.18/bin/python -I /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py Unknown option: -I usage: /home/philip/.pyenv/versions/2.7.18/bin/python [option] ... [-c cmd | -m mod | file | -] [arg] ... Try `python -h' for more information. at ChildProcess.exithandler (node:child_process:399:12) at ChildProcess.emit (node:events:526:28) at maybeClose (node:internal/child_process:1092:16) at Socket. (node:internal/child_process:451:11) at Socket.emit (node:events:526:28) at Pipe. (node:net:687:12)] { killed: false, code: 2, signal: null, cmd: '/home/philip/.pyenv/versions/2.7.18/bin/python -I /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py' } > ~/.pyenv/versions/3.10.4/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py [ERROR 2023-0-13 10:3:12.224]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/cdk-static-websites-AZV3rDYY doesn't contain a valid path to the project > ~/.local/share/virtualenvs/cdk-static-websites-AZV3rDYY/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py > ~/.local/share/virtualenvs/cdk-static-websites-zOm9C-Wd/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py [ERROR 2023-0-13 10:3:12.375]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/confluence-group-pages-vmmibARp doesn't contain a valid path to the project > ~/.local/share/virtualenvs/clo-ci-hook-OU6ckUa1/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py > ~/.local/share/virtualenvs/confluence-group-pages-_umzou8g/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py [ERROR 2023-0-13 10:3:12.471]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/confluence-page-updater-_P6vGlGI doesn't contain a valid path to the project [ERROR 2023-0-13 10:3:12.473]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/confluence-group-pages-vmmibARp doesn't contain a valid path to the project > ~/.local/share/virtualenvs/confluence-group-pages-vmmibARp/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py > ~/.local/share/virtualenvs/confluence-page-updater-OFi23sKt/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py [ERROR 2023-0-13 10:3:12.535]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/confluence-page-updater-_P6vGlGI doesn't contain a valid path to the project > ~/.local/share/virtualenvs/confluence-page-updater-_P6vGlGI/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py [ERROR 2023-0-13 10:3:12.564]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/github-action-scripts-hT4-2zLM doesn't contain a valid path to the project > ~/.local/share/virtualenvs/eks-billing-analysis-YhPQZTVO/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py > ~/.local/share/virtualenvs/exit-automation-9lqs4NWf/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py [ERROR 2023-0-13 10:3:12.643]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/github-action-scripts-hT4-2zLM doesn't contain a valid path to the project > ~/.local/share/virtualenvs/github-action-scripts-hT4-2zLM/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py [ERROR 2023-0-13 10:3:12.684]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/ldap-sanity-BphR30kE doesn't contain a valid path to the project > ~/.local/share/virtualenvs/jekyll-link-checker-WxNPQe40/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py [ERROR 2023-0-13 10:3:12.721]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/lifecycle-test-qM84hlPr doesn't contain a valid path to the project > ~/.local/share/virtualenvs/ldap-sanity-BQOcVU3w/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py [ERROR 2023-0-13 10:3:12.751]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/ldap-sanity-BphR30kE doesn't contain a valid path to the project > ~/.local/share/virtualenvs/ldap-sanity-BphR30kE/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py [ERROR 2023-0-13 10:3:12.779]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/lifecycle-test-qM84hlPr doesn't contain a valid path to the project > ~/.local/share/virtualenvs/lifecycle-test-qM84hlPr/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py > ~/.local/share/virtualenvs/lounge-maintenance-TCBpnHdh/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py > ~/.local/share/virtualenvs/meet-the-team---confluence-3171jp1c/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py > ~/.local/share/virtualenvs/octopus-import-x-Zfgh2O/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py > ~/.local/share/virtualenvs/resources.linaro.org-4AmrWW0f/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py > ~/.local/share/virtualenvs/sd-webhook-framework-zRqUmWf2/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py > ~/.local/share/virtualenvs/servicedesk-automation-tJXR8Tdr/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py [ERROR 2023-0-13 10:3:13.28]: [Error: Command failed: /home/philip/.local/share/virtualenvs/servicedesk-automation-tJXR8Tdr/bin/python -I /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py Unknown option: -I usage: /home/philip/.local/share/virtualenvs/servicedesk-automation-tJXR8Tdr/bin/python [option] ... [-c cmd | -m mod | file | -] [arg] ... Try `python -h' for more information. at ChildProcess.exithandler (node:child_process:399:12) at ChildProcess.emit (node:events:526:28) at maybeClose (node:internal/child_process:1092:16) at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)] { killed: false, code: 2, signal: null, cmd: '/home/philip/.local/share/virtualenvs/servicedesk-automation-tJXR8Tdr/bin/python -I /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py' } > /bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py > /usr/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py > ~/.pyenv/versions/3.10.4/bin/python3.10 -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py > ~/.pyenv/versions/2.7.18/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py [ERROR 2023-0-13 10:3:14.208]: [Error: Command failed: /home/philip/.pyenv/versions/2.7.18/bin/python -I /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py Unknown option: -I usage: /home/philip/.pyenv/versions/2.7.18/bin/python [option] ... [-c cmd | -m mod | file | -] [arg] ... Try `python -h' for more information. at ChildProcess.exithandler (node:child_process:399:12) at ChildProcess.emit (node:events:526:28) at maybeClose (node:internal/child_process:1092:16) at Socket. (node:internal/child_process:451:11) at Socket.emit (node:events:526:28) at Pipe. (node:net:687:12)] { killed: false, code: 2, signal: null, cmd: '/home/philip/.pyenv/versions/2.7.18/bin/python -I /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py' } > ~/.local/share/virtualenvs/servicedesk-automation-tJXR8Tdr/bin/python -I ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py ~/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py [ERROR 2023-0-13 10:3:15.53]: [Error: Command failed: /home/philip/.local/share/virtualenvs/servicedesk-automation-tJXR8Tdr/bin/python -I /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py Unknown option: -I usage: /home/philip/.local/share/virtualenvs/servicedesk-automation-tJXR8Tdr/bin/python [option] ... [-c cmd | -m mod | file | -] [arg] ... Try `python -h' for more information. at ChildProcess.exithandler (node:child_process:399:12) at ChildProcess.emit (node:events:526:28) at maybeClose (node:internal/child_process:1092:16) at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)] { killed: false, code: 2, signal: null, cmd: '/home/philip/.local/share/virtualenvs/servicedesk-automation-tJXR8Tdr/bin/python -I /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/get_output_via_markers.py /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/interpreterInfo.py' } [ERROR 2023-0-13 10:3:15.132]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/cdk-static-websites-AZV3rDYY doesn't contain a valid path to the project [ERROR 2023-0-13 10:3:15.144]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/cdk-static-websites-AZV3rDYY doesn't contain a valid path to the project [ERROR 2023-0-13 10:3:15.155]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/confluence-group-pages-vmmibARp doesn't contain a valid path to the project [ERROR 2023-0-13 10:3:15.164]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/confluence-page-updater-_P6vGlGI doesn't contain a valid path to the project [ERROR 2023-0-13 10:3:15.165]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/confluence-group-pages-vmmibARp doesn't contain a valid path to the project [ERROR 2023-0-13 10:3:15.173]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/confluence-page-updater-_P6vGlGI doesn't contain a valid path to the project [ERROR 2023-0-13 10:3:15.185]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/github-action-scripts-hT4-2zLM doesn't contain a valid path to the project [ERROR 2023-0-13 10:3:15.194]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/github-action-scripts-hT4-2zLM doesn't contain a valid path to the project [ERROR 2023-0-13 10:3:15.200]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/ldap-sanity-BphR30kE doesn't contain a valid path to the project [ERROR 2023-0-13 10:3:15.204]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/lifecycle-test-qM84hlPr doesn't contain a valid path to the project [ERROR 2023-0-13 10:3:15.214]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/ldap-sanity-BphR30kE doesn't contain a valid path to the project [ERROR 2023-0-13 10:3:15.218]: The .project file inside environment folder: /home/philip/.local/share/virtualenvs/lifecycle-test-qM84hlPr doesn't contain a valid path to the project DAP Server launched with command: /home/philip/.local/share/virtualenvs/sd-webhook-framework-zRqUmWf2/bin/python /home/philip/.vscode-server-insiders/extensions/ms-python.python-2023.1.10111008/pythonFiles/lib/python/debugpy/adapter ```

User Settings

``` languageServer: "Pylance" testing • pytestArgs: "" • pytestEnabled: true ```

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 |Item|Value| |---|---| |CPUs|11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz (8 x 2995)| |GPU Status|2d_canvas: enabled
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| |Load (avg)|undefined| |Memory (System)|15.84GB (3.63GB free)| |Process Argv|--folder-uri=vscode-remote://wsl+Ubuntu-20.04/home/philip/git/sd-webhook-framework --remote=wsl+Ubuntu-20.04 --crash-reporter-id 5232007f-9efe-473e-882d-54feb508997f| |Screen Reader|no| |VM|0%| |Item|Value| |---|---| |Remote|WSL: Ubuntu-20.04| |OS|Linux x64 5.15.79.1-microsoft-standard-WSL2| |CPUs|11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz (8 x 2995)| |Memory (System)|7.68GB (5.35GB free)| |VM|0%|
A/B Experiments ``` vsliv695:30137379 vsins829:30139715 vsliv368cf:30146710 vsreu685:30147344 python383cf:30185419 vspor879:30202332 vspor708:30202333 vspor363:30204092 vslsvsres303:30308271 pythonvspyl392:30422396 pythontb:30258533 pythonptprofiler:30281269 vshan820:30294714 pythondataviewer:30285072 vscod805:30301674 bridge0708:30335490 bridge0723:30353136 cmake_vspar411:30581797 vsaa593cf:30376535 pythonvs932:30404738 cppdebug:30492333 vsclangdf:30492506 c4g48928:30535728 dsvsc012cf:30540253 pynewext54:30618038 pylantcb52:30590116 pyindex848:30611229 nodejswelcome1:30587009 pyind779:30611226 pythonsymbol12cf:30622697 fim-prod:30623723 ```
int19h commented 1 year ago

Does it break if you manually call breakpoint() in your test?

pcolmer commented 1 year ago

@int19h

Does it break if you manually call breakpoint() in your test?

No, it doesn't - not in VS Code, at least. If I run pytest manually at the command line, it does drop into pdb.

int19h commented 1 year ago

This implies that the debugger doesn't get attached at all. By chance, are you using pytest-xdist or some similar facility that parallelizes test runs across multiple processes?

pcolmer commented 1 year ago

@int19h

By chance, are you using pytest-xdist or some similar facility that parallelizes test runs across multiple processes?

No - just plain pytest. Here is the settings file:

{
    "python.testing.pytestArgs": [
        "tests"
    ],
    "python.testing.unittestEnabled": false,
    "python.testing.pytestEnabled": true
}
Aisuko commented 1 year ago

Hi, guys. I hit the same issue. My breaking point is not working for the main function. I am in my codespace with Pylance v2023.1.40 Python v2022.20.2 Version: 1.74.3 (Universal) Commit: 97dec172d3256f8ca4bfb2143f3f76b503ca0534

Screenshot 2023-01-30 at 9 25 42 pm
int19h commented 1 year ago

Can you try enabling logging via "logToFile": true in your launch.json, and then sharing the logs after it fails to hit the breakpoints? It'll be a bunch of files named debugpy*.log on the remote machine under ~/.vscode-remote/extensions/ms-python*.

pcolmer commented 1 year ago

@int19h I don't have that directory. This is what I see in my home directory with those sort of filenames: image

pcolmer commented 1 year ago

I'm not finding anything called debugpy*.log in any of those .vscode directories, I'm afraid.

int19h commented 1 year ago

It should be under .vscode-server-insiders/extensions/ms-python* in this case, I think. In general, it's the parent directory of the path that you see in the terminal when you start debugging that has "pythonFiles" in it.

Can you check that "logToFile" setting is in the correct debug configuration? It should also have "purpose": ["debug-test"] in it for the test runner to apply it.

Alternatively, just set the environment variable DEBUGPY_LOG_DIR to the path where you want the logs to go. It should also be set on remote, though, such that it is in scope for the debugged process; I think the easiest would be to set it from the CLI before running code in WSL. If your debug config is "request": "launch", you should be able to use "env" in the config as well.

pcolmer commented 1 year ago

Just as a sanity check, here is my launch.json file:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "app.py",
                "FLASK_ENV": "development",
                "FLASK_DEBUG": "0"
            },
            "args": [
                "run",
                "--host",
                "0.0.0.0"
            ],
            "jinja": true,
            "logToFile": true
        }
    ]
}

If I add "purpose": ["debug-test"] and try to run a test, I get this error: image

I've tried setting the env:

            "env": {
                "FLASK_APP": "app.py",
                "FLASK_ENV": "development",
                "FLASK_DEBUG": "0",
                "DEBUGPY_LOG_DIR": "/home/philip/git/"
            },

but I'm still not seeing any debug logs, I'm afraid.

int19h commented 1 year ago

A config with "purpose": ["debug-test"] is basically a template from which the actual config is created when you do "Run Test", so it shouldn't have "program" or "module" in it - that part will be filled in to invoke pytest to run the test you've selected (although this could definitely use better diagnostics on VSCode side!).

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

Aisuko commented 1 year ago

Sorry for replying late, ms-python.python-2023.2.0 log file is below.

cd /workspaces/mit_6.006 ; /usr/bin/env DEBUGPY_LOG_DIR=/home/vscode/.vscode-server/extensions/ms-python.python-2023.2.0 /usr/local/python/current/bin/python /home/vscode/.vscode-server/extensions/ms-python.python-2023.2.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 49199 -- /workspaces/mit_6.006/02_code/test.py 

ms-python.tar.gz

int19h commented 1 year ago

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

Aisuko commented 1 year ago

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

github-actions[bot] commented 1 year ago

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.

AlviseSembenico commented 1 year ago

I'm also encountering the problem of breakpoint not being respected when debugging tests

kouyoumart commented 1 year ago

In my case, I had tried everything without success. I then just upgraded my Pytest version (to 7.3.1), and it worked. The debugger stops at the breakpoints again.

e7868a commented 9 months ago

In my case, I had tried everything without success. I then just upgraded my Pytest version (to 7.3.1), and it worked. The debugger stops at the breakpoints again.

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.

rwarren commented 1 month ago

@int19h - You said:

A config with "purpose": ["debug-test"] is basically a template from which the actual config is created when you do "Run Test", so it shouldn't have "program" or "module" in it - that part will be filled in to invoke pytest to run the test you've selected (although this could definitely use better diagnostics on VSCode side!).

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 "purpose": ["debug-test"] together with "request": "attach" for some reason. :(

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 purpose and debug-test are at these links (although they aren't helpful for this case right now):

int19h commented 1 month ago

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.

rwarren commented 1 month ago

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:

https://github.com/rwarren/DEMO_vscode_subprocess_debug

int19h commented 1 month ago

Normally I'd expect setting "subProcess" for the test config to work.

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.

rwarren commented 1 month ago

I posted the issue I was discussing above, with example, to the vscode-python-debugger project here:

https://github.com/microsoft/vscode-python-debugger/issues/461