microsoft / vscode-python-debugger

Python debugger (debugpy) extension for VS Code.
https://marketplace.visualstudio.com/items?itemName=ms-python.debugpy
MIT License
41 stars 17 forks source link

Unable to debug tests: Invalid message: Found duplicate in "env": PATH #261

Open DudeNr33 opened 3 months ago

DudeNr33 commented 3 months ago

Type: Bug

Plugin Versions

Python: v2024.2.1 Python Debugger: v2024.2.0

Behaviour

Expected vs. Actual

Expected: When selecting "debug test" from test runner or the editor, the debugger should start.

Actual: Debugger fails to start. Popup dialog with message "Invalid message: Found duplicate in "env": PATH." is displayed.

Steps to reproduce:

  1. Open a new folder in VS Code
  2. Add a single file with a dummy unit test like this:
    
    import unittest

class SomeTest(unittest.TestCase): def test_anything(self): self.assertTrue(True)

3. Configure Python tests
4. Try to debug the test

<!--
**After** creating the issue on GitHub, you can add screenshots and GIFs of what is happening. Consider tools like https://www.cockos.com/licecap/, https://github.com/phw/peek or https://www.screentogif.com/ for GIF creation.
-->

<!-- **NOTE**: Everything below except Python output panel is auto-generated; no editing required. Please do provide Python output panel. -->
# Diagnostic data

-   Python version (& distribution if applicable, e.g. Anaconda): 3.8.10
-   Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Global
-   Value of the `python.languageServer` setting: Default

<details>

<summary>Output for <code>Python</code> in the <code>Output</code> panel (<code>View</code>→<code>Output</code>, change the drop-down the upper-right of the <code>Output</code> panel to <code>Python</code>)
</summary>

<p>

2024-03-12 17:28:25.416 [debug] Found cached env for C:\Python38\python.exe 2024-03-12 17:28:25.421 [debug] starting server as TCP 2024-03-12 17:28:25.421 [debug] starting server as TCP 2024-03-12 17:28:25.423 [info] Using launch configuration in workspace folder. 2024-03-12 17:28:25.423 [debug] Found cached env for C:\Python38\python.exe 2024-03-12 17:28:25.423 [debug] Found cached env for C:\Python38\python.exe 2024-03-12 17:28:25.464 [debug] Activation Commands received undefined for shell cmd, resource c:\UserData\z003emnm\temp\duplicate_env_repro\test1 and interpreter C:\Python38\python.exe 2024-03-12 17:28:25.472 [debug] Found cached env for C:\Python38\python.exe 2024-03-12 17:28:25.473 [debug] Found cached env for C:\Python38\python.exe 2024-03-12 17:28:25.473 [debug] Found cached env for C:\Python38\python.exe 2024-03-12 17:28:25.478 [debug] CreateEnv Trigger - turned off in settings 2024-03-12 17:28:25.616 [debug] Found cached env for C:\Python38\python.exe 2024-03-12 17:28:25.634 [debug] Extension ms-python.debugpy accessed getActiveEnvironmentPath with args: undefined 2024-03-12 17:28:25.639 [debug] Extension ms-python.debugpy accessed resolveEnvironment with args: {"id":"C:\PYTHON38\PYTHON.EXE","path":"C:\Python38\python.exe"} 2024-03-12 17:28:25.647 [debug] Found cached env for C:\Python38\python.exe 2024-03-12 17:28:25.668 [debug] Extension ms-python.debugpy accessed resolveEnvironment with args: "C:\Python38\python.exe" 2024-03-12 17:29:10.882 [debug] Clearing context for python dependencies not installed: ms-python.python.Python 2024-03-12 17:29:10.883 [debug] Found cached env for C:\Python38\python.exe


</p>
</details>

<details>
<summary>Output for Python Debugger</summary>
<p>

2024-03-12 17:26:32.337 [info] Name: Python Debugger 2024-03-12 17:26:32.337 [info] Module: debugpy 2024-03-12 17:27:29.664 [info] DAP Server launched with command: C:\Python38\python.exe c:\Users\z003emnm.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter 2024-03-12 17:28:25.647 [info] DAP Server launched with command: C:\Python38\python.exe c:\Users\z003emnm.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter

</p>
</details>

<details>

<summary>User Settings</summary>

<p>

languageServer: "Pylance"

testing • unittestArgs: ["-v", "-s", ".", "-p", "test_*.py"] • unittestEnabled: true

experiments • enabled: false


</p>
</details>

Extension version: 2024.2.0
VS Code version: Code 1.87.0 (019f4d1419fbc8219a181fab7892ebccf7ee29a2, 2024-02-27T23:41:44.469Z)
OS version: Windows_NT x64 10.0.19045
Modes:

<details>
<summary>System Info</summary>

|Item|Value|
|---|---|
|CPUs|11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz (16 x 2496)|
|GPU Status|2d_canvas: enabled<br>canvas_oop_rasterization: enabled_on<br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: enabled<br>multiple_raster_threads: enabled_on<br>opengl: enabled_on<br>rasterization: enabled<br>raw_draw: disabled_off_ok<br>skia_graphite: disabled_off<br>video_decode: enabled<br>video_encode: enabled<br>vulkan: disabled_off<br>webgl: enabled<br>webgl2: enabled<br>webgpu: enabled|
|Load (avg)|undefined|
|Memory (System)|31.67GB (19.24GB free)|
|Process Argv|. --crash-reporter-id ad5562b9-4802-4e9d-83ef-990f176f3ed1|
|Screen Reader|no|
|VM|0%|
</details><details>
<summary>A/B Experiments</summary>

vsliv368cf:30146710 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscoreces:30445986 vscod805cf:30301675 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:30899288 c4g48928:30535728 azure-dev_surveyone:30548225 vscrp:30673768 962ge761:30959799 pythongtdpath:30769146 welcomedialog:30910333 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30936856 pyreplss1:30897532 pythonmypyd1:30879173 pythoncet0:30885854 pythontbext0:30879054 accentitlementsc:30887149 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 pydisww1:30981707 cppperfcontrol:30979541 8082a590:30971561 fegfb526:30981948 bg6jg535:30979843 dsvsc020:30976470



</details>

<!-- generated by issue reporter -->
DudeNr33 commented 3 months ago

I know there also exists https://github.com/microsoft/vscode-python/issues/10722, but as the debugger is now a separate extension I was not sure if this should now be handled in this repo?

DudeNr33 commented 3 months ago

I tried to reproduce this issue on a second Windows machine (Windows 11), but there it worked fine. The problem occurs on my work laptop with Windows 10.

What I also tried so far:

  1. Cleaned all contents from user settings.json: no success
  2. Disabled all extensions, only enabled Python and Python Debugger extension: no success

There is no .env file in the workspace:

C:.
│   test_something.py
│
├───.vscode
│       settings.json
│
└───__pycache__
        test_something.cpython-38.pyc

For reference, here is my full user settings.json:

User settings.json

```json { "workbench.startupEditor": "none", "workbench.editorAssociations": { "*.ipynb": "jupyter-notebook" }, "notebook.cellToolbarLocation": { "default": "right", "jupyter-notebook": "left" }, "terminal.integrated.defaultProfile.windows": "Command Prompt", "cmake.configureOnOpen": false, "csharp.suppressDotnetInstallWarning": true, "python.formatting.provider": "black", "[python]": { "editor.defaultFormatter": "ms-python.black-formatter", "editor.formatOnType": true }, "files.exclude": { "**/__pycache__": true, "**/*.pyc": true }, "testOnSave.testCommand": "", "python.defaultInterpreterPath": "C:\\Python38\\Scripts\\python.exe", "explorer.confirmDragAndDrop": false, "editor.formatOnSave": true, "workbench.iconTheme": "vscode-icons", "plantuml.server": "...", "plantuml.render": "PlantUMLServer", "remote.SSH.remotePlatform": { "dev-ec2": "linux", "ssm-dev-ec2": "linux" }, "redhat.telemetry.enabled": false, "vsicons.dontShowNewVersionMessage": true, "java.configuration.runtimes": [ { "name": "...", "path": "..." } ], "maven.settingsFile": "C:\\ProgramData\\chocolatey\\lib\\maven\\apache-maven-3.8.6\\conf\\settings.xml", "java.configuration.maven.userSettings": "C:\\ProgramData\\chocolatey\\lib\\maven\\apache-maven-3.8.7\\conf\\settings.xml", "testOnSave.languageId": "", "editor.stickyScroll.enabled": true, "git.autofetch": true, "markdown.validate.enabled": true, "git.confirmSync": false, "eslint.workingDirectories": ["frontend"], "workbench.colorTheme": "Default Dark+", "prettier.printWidth": 160, "[html]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "sonarlint.rules": { "python:S107": { "level": "off" } }, "java.configuration.maven.globalSettings": "C:\\ProgramData\\chocolatey\\lib\\maven\\apache-maven-3.8.7\\conf\\settings.xml", "java.configuration.updateBuildConfiguration": "automatic", "boot-java.rewrite.reconcile": true, "java.format.settings.url": "...", "[json]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "maven.terminal.useJavaHome": true, "explorer.confirmDelete": false, "[typescript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "prettier.singleQuote": true, "pylint.importStrategy": "fromEnvironment", "editor.renderWhitespace": "trailing", "robot.variables": {}, "editor.guides.bracketPairs": "active", "editor.detectIndentation": false, "window.zoomLevel": -1, "[markdown]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "jupyter.askForKernelRestart": false, "[jsonc]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "robot.completions.keywords.prefixImportName": true, "continue.telemetryEnabled": false, "continue.enableTabAutocomplete": false, "mypy-type-checker.importStrategy": "fromEnvironment", "mypy-type-checker.args": ["--ignore-missing-imports", "--implicit-optional"], "accessibility.signals.terminalQuickFix": { "sound": "on" }, "markdownlint.config": { "MD024": { "siblings_only": true } }, "python.experiments.enabled": false } ```

In addition, the config setting for Python: Env File is set to: ${workspaceFolder}/.env (both in User and in Workspace settings).

If there is any additional information that I can provide to help find the root cause, please let me know.

DudeNr33 commented 3 months ago

With the following launch.json debugging works:

{
  // 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 Debugger: Debug Test",
      "purpose": ["debug-test"],
      "type": "debugpy",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal"
    }
  ]
}

Changing console to internalConsole makes the issue reappear. Shouldn't this have been fixed via https://github.com/microsoft/vscode-python/pull/21033?