microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.33k stars 1.19k forks source link

"Restart debugging" button doesn't work when debugging tests #22576

Open shaperilio opened 11 months ago

shaperilio commented 11 months ago

I put this as the only configuration in my launch.json (taken from your docs)

{
  "name": "Python: Debug Tests",
  "type": "python",
  "request": "launch",
  "program": "${file}",
  "purpose": ["debug-test"],
  "console": "integratedTerminal",
  "justMyCode": false
}

I write a simple test and put a breakpoint in it. When the breakpoint is hit, I click on the restart debugging button: image

Debugging stops but the debugger that is started is not the one that runs unit tests; maybe related to #22530.

In the terminal, the first debug run puts out this command:

& 'c:\Users\1\repo\venv\Scripts\python.exe' 
'c:\Users\1\.vscode\extensions\ms-python.python-2023.4.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '51632' 
'--' 
'c:\Users\1\.vscode\extensions\ms-python.python-2023.4.1\pythonFiles\testlauncher.py' 
'c:\Users\1\repo' 'pytest' '--rootdir' 'c:\Users\1\repo' '--override-ini' 'junit_family=xunit1' '--junit-xml=C:\Users\1\AppData\Local\Temp\tmp-30092H3SpqtSp80pj.xml' '-vv' '--capture' 'no' './tests/test_file.py::test_foo'

The restart does this:

c:; cd 'c:\Users\1\repo'; 
& 'c:\Users\1\repo\venv\Scripts\python.exe' 
'c:\Users\1\.vscode\extensions\ms-python.python-2023.4.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '51716' 
'--' 
'C:\Users\1\repo\tests\test_file.py'

The difference is the actual command being run.

Version: 1.84.2 (user setup) Commit: 1a5daa3a0231a0fbba4f14db7ec463cf99d7768e Date: 2023-11-09T10:51:52.184Z Electron: 25.9.2 ElectronBuildId: 24603566 Chromium: 114.0.5735.289 Node.js: 18.15.0 V8: 11.4.183.29-electron.0 OS: Windows_NT x64 10.0.19045

Python extension version v2023.20.0

paulacamargo25 commented 10 months ago

Thanks for your bug report, i could repo the error.