Open asipras opened 4 years ago
Same Python extension version 2020.3.69010
and the same problem with debugging pytest tests.
In my case, I can't see any error log even when selecting Python Test Log
as output (Is there another way to see complete logs?). When running the tests without debugging, everything works fine and I can see something logged in the console.
For some reason, trying to install a different version of the Python extension doesn't work.
Everything used to work until a few days ago when I was using the extension version 2020.2.64397
My system is different, here are the details
Version: 1.42.1
Commit: c47d83b293181d9be64f27ff093689e8e7aed054
Date: 2020-02-17T09:32:31.598Z
Electron: 6.1.9
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Linux x64 5.5.8-1-MANJARO
I am using pipenv
, so I am using venv
(the python version selected by VScode is correct).
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 the Output
panel to Python
).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:
For some reason, trying to install a different version of the Python extension doesn't work.
Thanks!
@kimadeline thanks for looking into this. I did downgrade to the previous version of python extension 2020.2.64397 and now i am able to debug the tests.
I also did some debugging with the latest version of python extension 2020.3.69010. I was able to debug a simple test (does not reference any 3rd party modules numpy, scipy, etc.) by invoking VS code from normal command prompt. However when I invoked VS code using Anaconda prompt/terminal I got the error message mentioned above.
The log from the python output panel.
> ~\Anaconda3\envs\mounthood-dev\python.exe -m site --user-site
cwd: c:\src\Test
> ~\Anaconda3\envs\mounthood-dev\python.exe -m site --user-site
cwd: c:\src\Test
> ~\Anaconda3\envs\mounthood-dev\python.exe completion.py
cwd: c:\Users\asif.prasla\.vscode\extensions\ms-python.python-2020.3.69010\pythonFiles
> ~\Anaconda3\envs\mounthood-dev\python.exe completion.py
cwd: c:\Users\asif.prasla\.vscode\extensions\ms-python.python-2020.3.69010\pythonFiles
> ~\Anaconda3\envs\mounthood-dev\python.exe -m pylint --disable=all --enable=F,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,unused-wildcard-import,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode,E0001,E0011,E0012,E0100,E0101,E0102,E0103,E0104,E0105,E0107,E0108,E0110,E0111,E0112,E0113,E0114,E0115,E0116,E0117,E0118,E0202,E0203,E0211,E0213,E0236,E0237,E0238,E0239,E0240,E0241,E0301,E0302,E0303,E0401,E0402,E0601,E0602,E0603,E0604,E0611,E0632,E0633,E0701,E0702,E0703,E0704,E0710,E0711,E0712,E1003,E1101,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1128,E1129,E1130,E1131,E1132,E1133,E1134,E1135,E1136,E1137,E1138,E1139,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,E1310,E1700,E1701 --msg-template='{line},{column},{category},{symbol}:{msg}' --reports=n --output-format=text c:\src\Test\tests\test_one.py
cwd: c:\src\Test
> ~\Anaconda3\envs\mounthood-dev\python.exe -m pylint --disable=all --enable=F,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,unused-wildcard-import,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode,E0001,E0011,E0012,E0100,E0101,E0102,E0103,E0104,E0105,E0107,E0108,E0110,E0111,E0112,E0113,E0114,E0115,E0116,E0117,E0118,E0202,E0203,E0211,E0213,E0236,E0237,E0238,E0239,E0240,E0241,E0301,E0302,E0303,E0401,E0402,E0601,E0602,E0603,E0604,E0611,E0632,E0633,E0701,E0702,E0703,E0704,E0710,E0711,E0712,E1003,E1101,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1128,E1129,E1130,E1131,E1132,E1133,E1134,E1135,E1136,E1137,E1138,E1139,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,E1310,E1700,E1701 --msg-template='{line},{column},{category},{symbol}:{msg}' --reports=n --output-format=text c:\src\Test\tests\test_one.py
cwd: c:\src\Test
> conda env list
##########Linting Output - pylint##########
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
> ~\Anaconda3\envs\mounthood-dev\python.exe c:\Users\asif.prasla\.vscode\extensions\ms-python.python-2020.3.69010\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir c:\src\Test -s --cache-clear tests
cwd: c:\src\Test
> ~\Anaconda3\envs\mounthood-dev\python.exe -c "import notebook"
> ~\Anaconda3\envs\mounthood-dev\python.exe -c "import jupyter"
@kimadeline thanks for taking the time to look into this.
First, I updated my system and VScode to be on the latest version, these are the info
Version: 1.43.1
Commit: fe22a9645b44368865c0ba92e2fb881ff1afce94
Date: 2020-03-21T21:58:41.223Z
Electron: 7.1.14
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Linux x64 5.5.11-1-MANJARO
This is my settings.json
. The virtualenv is created through pipenv
{
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.pythonPath": "/home/lorenzo/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python",
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
"python.formatting.provider": "yapf"
}
This is a repo that gives me issues when trying to debug tests https://github.com/SwissDataScienceCenter/renku-python
Let's say I try to debug test_init_repository
. When I click on Run Test
, the test is marked as succesfull and the Python output panel is
> ~/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python -m pytest --rootdir ~/development/sdsc/renku-python --junitxml=/tmp/tmp-3682KwykJulSvoSV.xml ./tests/core/management/test_repository.py::test_init_repository
cwd: ~/development/sdsc/renku-python
When clicking on Debug Test
with a breakpoint anywhere in the code, let's say at line 27, the debug shorty start (I can see the buttons "play", "stop", ... on the top) but it stops after 1 or 2 seconds without any warning. There is no output at all in the Python output panel.
Not sure if this is useful, but the initial output I see in the Python output panel after starting VScode is the following
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'ShowExtensionSurveyPrompt - control'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'PtvsdWheels37 - experiment'
User belongs to experiment group 'Reload - control'
User belongs to experiment group 'LS - control'
User belongs to experiment group 'UseTerminalToGetActivatedEnvVars - control'
User belongs to experiment group 'WebHostNotebook - control'
User belongs to experiment group 'CollectLSRequestTiming - control'
User belongs to experiment group 'CollectNodeLSRequestTiming - experiment'
> conda --version
> pyenv root
> python3.7 -c "import sys;print(sys.executable)"
> python3.6 -c "import sys;print(sys.executable)"
> python3 -c "import sys;print(sys.executable)"
> python2 -c "import sys;print(sys.executable)"
> python -c "import sys;print(sys.executable)"
> ~/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python -c "import sys;print(sys.executable)"
> conda info --json
> pipenv --version
cwd: ~/development/sdsc/renku-python
> pipenv --version
cwd: ~/development/sdsc/renku-python
> pipenv --venv
cwd: ~/development/sdsc/renku-python
> pipenv --venv
cwd: ~/development/sdsc/renku-python
> ~/.local/share/virtualenvs/renku-notebooks-4n1SxYW5/bin/python -c "import notebook"
> ~/.local/share/virtualenvs/renku-notebooks-4n1SxYW5/bin/python -c "import jupyter"
> pipenv --py
cwd: ~/development/sdsc/renku-python
> pipenv --py
cwd: ~/development/sdsc/renku-python
Starting Jedi Python language engine.
> ~/.local/share/virtualenvs/renku-notebooks-4n1SxYW5/bin/python -m jupyter kernelspec --version
> conda --version
> ~/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.3.69010/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/development/sdsc/renku-python -s --cache-clear
cwd: ~/development/sdsc/renku-python
> ~/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python -c "import sys;print(sys.prefix)"
cwd: ~/development/sdsc/renku-python
> ~/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python -c "import sys;print(sys.prefix)"
cwd: ~/development/sdsc/renku-python
> ~/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python -c "import sys;print(sys.executable)"
cwd: ~/development/sdsc/renku-python
> ~/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python -c "import sys;print(sys.executable)"
cwd: ~/development/sdsc/renku-python
> ~/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: ~/development/sdsc/renku-python
> ~/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: ~/development/sdsc/renku-python
> ~/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python -m site --user-site
cwd: ~/development/sdsc/renku-python
> ~/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python -m site --user-site
cwd: ~/development/sdsc/renku-python
> ~/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python completion.py
cwd: ~/.vscode-oss/extensions/ms-python.python-2020.3.69010/pythonFiles
> ~/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python completion.py
cwd: ~/.vscode-oss/extensions/ms-python.python-2020.3.69010/pythonFiles
> ~/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python -m flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/development/sdsc/renku-python/tests/cli/test_init.py
cwd: ~/development/sdsc/renku-python
> ~/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python -m flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/development/sdsc/renku-python/tests/cli/test_init.py
cwd: ~/development/sdsc/renku-python
##########Linting Output - flake8##########
Even when downgrading the Python extension to 2020.2.64397
, I get the very same behavior. Sorry for my previous statement, I was convinced it was related to the Python extension version since debugging tests stopped working the same day the extension was updated.
Breakpoints somewhere else in the code seem to work when debugging with the remote attach, so the issue seems to be limited to debugging tests. At this point, I believe this is related to my system, but any help in further understanding how to fix this would be greatly appreciated.
I have tried on another system (Ubuntu 18.04) and I initially got the very same result.
After trying many things, I was able to debug by commenting out in pytest.ini the line addopts = --flake8 --pep8 [...]
:raised_hands:
For some reason, this seems to work on Ubuntu but not on my initial system Manjaro :sob: .
I also tried to uninstall VSCode and remove the config files ($HOME/.vscode
and $HOME/.config/Code
), but this didnt't help.
I am wondering if there is a detailed log I can look at to get extra infomation :thinking:
@asipras Can you add the following configuration to your launch.json
:
{
"name": "Python: Test debug config",
"type": "python",
"request": "test",
"console": "integratedTerminal",
"logToFile": true
}
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:
No, I don't get that message. I guess my problem is unrelated to @asipras 's one
Other info: if I open the Developer Tools I get the following message when successfully running the tests
[Extension Host] Info Python Extension: 2020-03-25 11:24:26: getActivatedEnvironmentVariables, Class name = C, completed in 0ms, has a truthy return value, Arg 1: <Uri:/home/lorenzo/development/sdsc/renku-python>, Arg 2: undefined, Arg 3: undefined
console.ts:137 [Extension Host] Info Python Extension: 2020-03-25 11:24:26: > ~/.local/share/virtualenvs/renku-python-WcnE3QeY/bin/python -m pytest --rootdir ~/development/sdsc/renku-python --junitxml=/tmp/tmp-10951bUxBnRjlaHFD.xml ./tests/core/management/test_repository.py::test_init_repository
console.ts:137 [Extension Host] Info Python Extension: 2020-03-25 11:24:26: cwd: ~/development/sdsc/renku-python
and I get this error when trying to debugging the test
ERR timeout after 500 ms: Error: timeout after 500 ms
at t.RawDebugSession.handleErrorResponse (file:///usr/lib/code/out/vs/workbench/workbench.desktop.main.js:2954:952)
at file:///usr/lib/code/out/vs/workbench/workbench.desktop.main.js:2954:250
at async t.RawDebugSession.shutdown (file:///usr/lib/code/out/vs/workbench/workbench.desktop.main.js:2952:336)
Here with more details from the Log (Window)
[2020-03-25 15:05:19.148] [renderer1] [error] timeout after 500 ms: Error: timeout after 500 ms
at t.RawDebugSession.handleErrorResponse (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:2954:952)
at file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:2954:250
at async t.RawDebugSession.shutdown (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:2952:336)
[2020-03-25 15:05:20.859] [renderer1] [error] TreeError [CustomView] Data tree node not found: [object Object]: Error: TreeError [CustomView] Data tree node not found: [object Object]
at H.getDataNode (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:1097:771)
at H._updateChildren (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:1095:64)
at H.updateChildren (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:1094:798)
at file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:5773:30
at Array.map (<anonymous>)
at G.doRefresh (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:5773:21)
at G.refresh (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:5772:111)
at p.$refresh (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:3671:510)
at g._doInvokeHandler (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:3681:363)
at g._invokeHandler (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:3681:55)
at g._receiveRequest (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:3679:739)
at g._receiveOneMessage (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:3678:518)
at file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:3676:754
at c.fire (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:110:24)
at v.fire (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:382:801)
at t.PersistentProtocol._receiveMessage (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:387:276)
at file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:384:321
at c.fire (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:110:24)
at g.acceptChunk (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:380:306)
at file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:379:657
at Socket.t (file:///opt/visual-studio-code/resources/app/out/vs/workbench/workbench.desktop.main.js:390:450)
at Socket.emit (events.js:203:13)
at addChunk (_stream_readable.js:295:12)
at readableAddChunk (_stream_readable.js:276:11)
at Socket.Readable.push (_stream_readable.js:210:10)
at Pipe.onStreamRead (internal/stream_base_commons.js:166:17)
P.S. sorry for the spam, I am really mad about this, I tried so many things to fix... :man_facepalming:
@lorenzo-cavazzi since you said that you still can't debug tests with a previous version of the extension, that it suddenly stopped working, and that it worked on Ubuntu but not on Manjaro I suspect that it's something specific to your setup and not the extension. Have you tried asking on Stack Overflow?
In any case, since your problem is unrelated to the original one, please open a separate issue with all your comments merged in one.
I tried anything I could find by googling but I couldn't fix it. Maybe there is something else I can try in order to debug? I opened another issue here #10778
{ "name": "Python: Test debug config", "type": "python", "request": "test", "console": "integratedTerminal", "logToFile": true }
@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.
{
// 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: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "Python: Test debug config",
"type": "python",
"request": "test",
"console": "integratedTerminal",
"logToFile": true
}
]
}
debugpy.adapter-27144.log debugpy.launcher-29020.log debugpy.pydevd.24988.log debugpy.server-24988.log
Thanks for trying it!
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.
This is puzzling 🤔 Somehow the explicit test config does (or doesn't do) something that the default config does, which doesn't add the duplicate value and solves your issue.
Can you try something else? Since getting the logs this way has the unintended effect of solving your issue, let's try retrieving the logs a different way:
DEBUGPY_LOG_DIR
environment variable to point at a destination directory for the logs;This way we can compare the logs, and see what the default config sets behind the scenes.
Thanks!
cc @int19h
@kimadeline I did get the logs with latest python extension and removing the test configuration that you suggested earlier. I got the same error. I am uploading those log files Logs_with_error.zip.
I deleted all the log files added the test configuration to launch.json and debugger worked. I am attaching those log files Logs_without_error.zip Logs_without_error.zip Logs_with_error.zip
It seems that the default configuration has all environment variables copied into "env" by the extension. And then on top of that, somehow this ends up with two path variables - there's "Path" and "PATH" in JSON, both with the same value. This doubling is what's triggering the error.
I believe this is the code that's doing the copying: https://github.com/microsoft/vscode-python/blob/0ba42da331103036e7dab7b73e4585a028570fce/src/client/debugger/extension/configuration/resolvers/helper.ts#L50-L62
This is wrong for debugpy - the extension is only spawning the adapter, and "env" doesn't apply to it. Instead, the adapter itself will parse "env" and use it to spawn the debuggee correctly, so none of this code should be applicable.
Furthermore, this code also works with variables in a case-sensitive manner, even on Windows. Note how, after calling mergeVariables()
, it tries to manually tweak PYTHONPATH
and path, the latter retrieved via getPathVariableName()
. This ends up here:
https://github.com/microsoft/vscode-python/blob/0ba42da331103036e7dab7b73e4585a028570fce/src/client/common/platform/fs-paths.ts#L88-L90
This abstraction is pointless, because there's no guarantee whatsoever that Path
is how it's always capitalized on Windows - indeed, in this case, it was not. Nor is there any guarantee that PYTHONPATH
is spelled with all caps. The code that's dealing with either one of those just has to account for names being case-insensitive on Windows, and merge accordingly.
(This entire function is wrong for debugpy, actually - it shouldn't be setting any other specific environment variables like PYTHONIOENCODING
or GEVENT
. It should only be handling .envFile
, reading entries from there, and adding them to "env".)
Thank you @asipras and @int19h!
@asipras this is an issue on our end, so until we fix it you'll have to use the test configuration in your launch.json
as a workaround.
Further discussion with @int19h:
Path is spelled "PATH" on all platforms, so we don't really need a service for that. What we do need is a helper library to work with objects that are really collections of environment variables (like
process.env
), which enforce OS behavior - i.e. case insensitive keys on Windows.BTW, apparently Node itself does it correctly for
process.env
: On Windows operating systems, environment variables are case-insensitive.process.env.TEST = 1; console.log(process.env.test); // => 1
I had this exact same issue and, yes, after adding that configuration to my launch.json, I'm now able to debug my code. So the workaround... works.
2020.2.64397 can not work. 2019,can work
I'm having this same problem, and using the test configuration to my launch.json does not alleviate the issue. For what it's worth, I know that I'm in some kind of A/B test group from an experience a few months ago which prevented me from debugging unit tests. I can go through steps to provide logs if you'd like, but it seems like you've already found the source of the problem. I guess for now I will try to figure out how to downgrade to the previous version and see if that helps, but I wanted to add my report because the behavior differs slightly from the other reports, and because I'd like an update when the issue is fixed.
Worked around issue by downgrading Python extention to v2020.2.64397, reloading extension and then exiting and restarting VSCode. Curiously, it now reports a problem in test discovery, although it seems to be discovering tests successfully regardless of the error. At any rate, I'm hoping to hear that this issue is fixed in the next release. Please let me know if there's anything I can do to help. If it's useful to you at all, I've had the PTVSD_LOG_DIR environment set on my system since the last time I reported an issue, so I have plenty of logs from that which I can supply ;)
@asipras Can you add the following configuration to your
launch.json
:{ "name": "Python: Test debug config", "type": "python", "request": "test", "console": "integratedTerminal", "logToFile": true }
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:
This also worked for me.
@amandalishus Are you seeing the same error message about "Duplicate entries in "env"
"? If not, it is likely to be a different issue - please file it separately.
@int19h Catch the same bug in v2020.8.101144. My decision was to rename from "PATH" to "Path" in system environment variables.
Perhaps it will be useful to someone.
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:
env_change = { k.upper(): v for k, v in env_changes.items() }
Comment this line out:
# env_change = { k.upper(): v for k, v in env_changes.items() }
I have to do this when I restart code, but this allows me to do debugging.
Note that the above change just turns it from a diagnosable error to (potential) silently wrong behavior, because you might end up with both "Path" and "PATH" in the environment, and it's non-deterministic as to which one will be actually used for the debuggee. The proper fix would be on the extension side (although you can't easily hot-patch it like you can with debugpy).
Here are some observations while dealing with this issue, maybe this will help someone, Python v2021.5.842923320:
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.
@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:
{
"name": "Python: Test debug config",
"type": "python",
"request": "test",
"console": "integratedTerminal",
"logToFile": true
}
to launch.json
resolves the problem.
Amazing that this problem still exists nearly two years later.
@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?
@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?
I am facing the same issue.
What worked for me just now...
I found that there was a "PythonPath" env variable set on my user profile. I think, as per above, that case sensitivity on this was confusing vscode.
I've deleted it - rebooted - and now debug works just fine.
@kimadeline is there a fix? Im still facing the same issue! I have also opened a stackoverflow thread for it : https://stackoverflow.com/questions/72717904/visual-studio-code-vs-code-run-test-button-works-fine-but-debug-test-does-not
cc @karthiknadig
@panos23kar Looking at the SO issue the module not found problem is often due to environment not being activated. Can you file a separate bug for your scenario with output logs and type of environment you are using.
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.
For some reason this problem repeated in version 2023.3.10411009
. In my case Path
is simply PATH
twice, PYTHONPATH
also just duplicate of itself.
this might help someone, here is part of lanuch.json which finally worked with pytest
{
"name": "PyTest",
"type": "python",
"request": "test",
"stopOnEntry": false,
"module": "pytest",
"console": "integratedTerminal",
"logToFile": true,
"args": [
"-v",
],
"cwd": "${fileDirname}",
"env": {
"PYTEST_ADDOPTS": "--no-cov"
},
},
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)
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.
@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:
{
"name": "Python: Test debug config",
"type": "python",
"request": "test",
"console": "integratedTerminal",
"logToFile": true
}
I just ignored the linting error on "request" type.
The equivalent configuration to the deprecated way above looks like:
launch.json
{
"name": "Python: Test debug config",
"type": "python",
"request": "launch",
"console": "integratedTerminal",
"purpose": ["debug-test"],
"logToFile": true
}
See this debug recommendation...
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
Adding to the buzz. Same issue, same solution with the workaround. My versions:
Version: 1.77.0 (user setup)
Commit: 7f329fe6c66b0f86ae1574c2911b681ad5a45d63
Date: 2023-03-29T10:02:16.981Z
Electron: 19.1.11
Chromium: 102.0.5005.196
Node.js: 16.14.2
V8: 10.2.154.26-electron.0
OS: Windows_NT x64 10.0.22000
Sandboxed: No
Same issue, the "tests" fix did not work and I had to downgrade the extension
Same issue, @blakeNaccarato's solution works for version v2023.6.0 but i would have to add in all projects. I do not like that. I go back to version v2023.4.1 that does not have the problem
Note that my config above probably fixes things as a side-effect, maybe by logging errors to a file instead of surfacing them and breaking the flow. The config is actually meant for generating logs to share with devs for fixing bugs such as these.
In a (probably) related issue the devs say they are working on fixing the bug as soon as possible. Since both of these issues cropped up in the latest release, and both are related to VSCode debugging, it is likely they share the root cause of duplicated environment variables with different values.
Same - downgrade Python extension to v2023. 4.1 solved the issue.
This seems to be fixed in the pre-release version (I'm on v2023.7.11011538)
This worked for me:
{
"name": "Python: Pytest",
"type": "python",
"request": "test", // <----- this is for tests
"args": [
"-v" // verbose
],
"console": "integratedTerminal"
}
Now my full settings.json
file looks like this:
{
// 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: FastAPI",
"type": "python",
"request": "launch",
"module": "uvicorn",
"args": [
"api.main:app"
],
"jinja": true,
"justMyCode": true
},
{
"name": "Python: Pytest",
"type": "python",
"request": "test", // <----- this is for tests
"args": [
"-v" // verbose
],
"console": "integratedTerminal"
}
]
}
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 }
Hello! We have just finished our testing rewrite and are beginning the rollout to users. It seems some of you have tried it and I am not sure if it was on the rewrite or not. You can confirm using the steps below. If everyone engaging on this post recently could try it on the rewrite it would be very helpful to know if your issues still exists on the rewrite! To try it yourself, you need to be on the most recent release of the Python extension and add this setting to your users settings.json
"python.experiments.optInto": ["pythonTestAdapter"]
.
You can confirm you have the rewrite enabled by setting "python.analysis.logLevel": "Trace",
in your user settings then check for Experiment 'pythonTestAdapter'
is active in your python logs.
Let me know if the rewrite fixes your issue. Thanks!
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
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)