vscode-python: Debugging test in VS Code does not work
Environment data
Version: 1.43.1 (user setup) Commit: fe22a9645b44368865c0ba92e2fb881ff1afce94 Date: 2020-03-18T07:01:20.184Z Electron: 7.1.11 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Windows_NT x64 10.0.18363
- Python version (& distribution if applicable, e.g. Anaconda): Python Anaconda 3.7.6 64-bit
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): Anaconda 1.9.12
- Relevant/affected Python packages and their versions: Python 2020.3.69010
- Relevant/affected Python-related VS Code extensions and their versions: Python 2020.3.69010
Expected behaviour
Debugging test should work.
Actual behaviour
Debugging test does not work. VS code shows error dialog. See in reproduction steps for more details. If I run the test without debugger the tests runs as expected.
Steps to reproduce:
Try to debug tests using unit test library, Click on the small bug icon for an individual test to debug. I get a dialog box error saying Invalid message: Duplicate entries in “env”. The two options i get are Open launch.json and Cancel.
I have checked my lauch.json and I do not have duplicate entries for any env variable.
Logs
ERR timeout after 500 ms: Error: timeout after 500 ms at t.RawDebugSession.handleErrorResponse (file:///C:/Users/AP/AppData/Local/Programs/Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2954:952) at file:///C:/Users/AP/AppData/Local/Programs/Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2954:250 at async t.RawDebugSession.shutdown (file:///C:/Users/AP/AppData/Local/Programs/Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2952:336)
### Settings.json
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true
}
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 14
- Comments: 59 (6 by maintainers)
@asipras Can you add the following configuration to your
launch.json
:Try debugging your tests, and copy here the content of the
debugpy*.log
file from the extension folder.@lorenzo-cavazzi are you getting the same
Duplicate entries in "env"
message? If that’s the case, there is something else going on in your setup that’s not related to the extension, because it’s a Windows-specific error message from the debugger:https://github.com/microsoft/debugpy/blob/69db68a5f9aff6c1dfd955c8934c753212f94633/src/debugpy/launcher/handlers.py#L110-L119
@shaperilio Same issue here. I was able to fix by adding the following to launch.json per instructions from a few years ago in thread above:
I just ignored the linting error on “request” type.
Same - downgrade Python extension to v2023. 4.1 solved the issue.
Not sure why this issue is just sitting here, but it’s come up again. When I try to debug a test with the Python Extension version v2023.6.0, I get
"Invalid message: Found duplicate in "env": PATH
Version 2023.4.1 works just fine.
The error message is not helpful; it certainly makes it seem like I should know what to do with
launch.json
.I tried to turn on logging as suggested above, but I can’t find the log file… no idea if that setting is still valid.
I am facing the same issue.
@robinstauntoncollins I can confirm this launch config is working.
Unfortunately then VS Code complains “test” isn’t a valid value for
request
. Valid values are “launch” or “attach”. Is there any solution/workaround for this?Same issue here, no longer possible to debug my python tests suite after updating to v2023.6.0. None of the configuration metioned above solve the problem for me.
Back to work after downgrading to v2023.4.1
This seems to be fixed in the pre-release version (I’m on v2023.7.11011538)
I found out, that in my case the duplicate entries error occures when I launch VS Code vie terminal using Git Bash.
When I launch it by desktop shortcut everything works fine.
this might help someone, here is part of lanuch.json which finally worked with pytest
if using pytest and coverage, debugger won’t break – so py-cov needs deactivating
also, request needs to be
test
(even if vscode complains about it being invalid)@lhotamir Same for me. Launching using
code .
from Git Bash terminal results in this error when trying to test: Invalid message: Found duplicate in “env”: PATH.Launching using Windows shortcut or adding:
to
launch.json
resolves the problem.Amazing that this problem still exists nearly two years later.
Just in case someone is having the same problems I was having and can’t get this to work at all but needs it to, this is how i get it to work for me. I actually modify the handlers.py file located at
%HOMEPATH%\.vscode\extensions\ms-python.python-xxx.x.xxxx\pythonFiles\lib\python\debugpy\launcher\handlers.py
I comment out the lines that checks for duplicate entries:
Around line 89 you will see:
Comment this line out:
I have to do this when I restart code, but this allows me to do debugging.
@kimadeline I did what you suggested. Below is my launch.json. What is amazing is now I can debug test using latest version of python extension 2020.03.69010. If I remove the configuration that you suggested from my launch,json then I get the same error.
debugpy.adapter-27144.log debugpy.launcher-29020.log debugpy.pydevd.24988.log debugpy.server-24988.log
To me this issue does not seem to be fixed. I am currently running v2023.22.1 of the plugin together with behave.
Error message is exaclty the same one as reported initially.
When I downgrade to 2023.8.0 it will work again.
The following did not help:
For me I’m using unittest not Pytest but by changing the settings.json to this fixed it for me:
{ “python.testing.unittestArgs”: [ “-v”, “-s”, “${workspaceFolder}/”, “-p”, “test.py” ], “python.testing.pytestEnabled”: false, “python.testing.unittestEnabled”: true }
The equivalent configuration to the deprecated way above looks like:
launch.json
See this debug recommendation…
https://github.com/microsoft/vscode-python/blob/5528e0efb9b8c91c83dfb356391085280fb63417/src/client/debugger/extension/configuration/debugConfigurationService.ts#L75
For some reason this problem repeated in version
2023.3.10411009
. In my casePath
is simplyPATH
twice,PYTHONPATH
also just duplicate of itself.Still the same issue here. It feels very frustrating cause the debug functionality is used by everyone at my company and we always need to downgrade the extension to the 8.1 version.
Hello @asipras and @lorenzo-cavazzi, thank you for reaching out.
Can I ask you both to provide the following:
.vscode/settings.json
is sadly not enough for me to replicate this issue, I can debug tests correctly);Python
output panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
).Can you also confirm that if you downgrade to the previous release of the extension (
2020.2.64397
) you can debug tests correctly:@lorenzo-cavazzi what do you mean by that:
Thanks!