Skip to content

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

Description

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)
  1. Configure Python tests
  2. Try to debug the test

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
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)

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

Output for Python Debugger

``` 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 ```

User Settings


languageServer: "Pylance"

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

experiments
• enabled: false

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:

System Info
Item Value
CPUs 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz (16 x 2496)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
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_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
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%
A/B Experiments
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

Activity

  1. DudeNr33 commented on Mar 12, 2024

    @DudeNr33
    Author

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

  2. DudeNr33 commented on Mar 13, 2024

    @DudeNr33
    Author

    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

    {
        "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.

  3. DudeNr33 commented on Mar 18, 2024

    @DudeNr33
    Author

    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 microsoft/vscode-python#21033?

  4. added
    bugIssue identified by VS Code Team member as probable bug
    needs PRReady to be worked on
    and removed
    triage-neededNeeds assignment to the proper sub-team
    on Apr 24, 2024
  5. eleanorjboyd commented on Sep 18, 2024

    @eleanorjboyd
    Member

    Hello! Sorry for the delay but are you still experiencing this issue?

  6. DudeNr33 commented on Sep 23, 2024

    @DudeNr33
    Author

    Hi! Yes, the issue still exists. The workaround with the modified launch.json and the use of "console": "integratedTerminal" is still required.

    I am using the current version 1.93.1:

    Version: 1.93.1 (system setup)
    Commit: 38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40
    Date: 2024-09-11T17:20:05.685Z
    Electron: 30.4.0
    ElectronBuildId: 10073054
    Chromium: 124.0.6367.243
    Node.js: 20.15.1
    V8: 12.4.254.20-electron.0
    OS: Windows_NT x64 10.0.19045
    
  7. rwijtvliet commented on Oct 7, 2024

    @rwijtvliet

    Just to add a datapoint: I have the same issue. I'm also on Win10, but I get the error regardless of launch.json having "console": "integratedTerminal" or "console": "internalConsole".

  8. rwijtvliet commented on Oct 21, 2024

    @rwijtvliet

    I found what caused the issue for me. There was an incorrect entry in the Path environment variable in windows. There was a folderpath which contained a /, which is forbidden under windows. (Going from the name, it was caused by GlazeWM, but I'm not pointing fingers.)

    After removing the entry, I could debug tests again.

    Hope that is helpful for some of you; maybe the error message could be improved to reflect this possible error source.

  9. ChenShiChao commented on Mar 19, 2025

    @ChenShiChao

    tmp modify handler.py:

    if sys.platform == "win32":
        # Environment variables are case-insensitive on Win32, so we need to normalize
        # both dicts to make sure that env vars specified in the debug configuration
        # overwrite the global env vars correctly. If debug config has entries that
        # differ in case only, that's an error.
        env = {k.upper(): v for k, v in os.environ.items()}
        new_env_changes = {}
        for k, v in env_changes.items():
            k_upper = k.upper()
            if k_upper in new_env_changes:
                if new_env_changes[k_upper] == v:
                    continue
                else:
                    # modify by chenshichao  2025.03.19
                    if True:
                        new_env_changes[k_upper] = f"{new_env_changes[k_upper]}:{v}"
                    else:
                        raise request.isnt_valid(
                            'Found duplicate in "env": {0}.'.format(new_env_changes[k_upper])
                        )
            new_env_changes[k_upper] = v
    
  10. eleanorjboyd commented on Mar 31, 2025

    @eleanorjboyd
    Member

    rwijtvliet what path was the incorrect entry in the Path environment variable in windows.? Is this something the debugger extension added because if so I can investigate a fix there. Otherwise the error message update would be useful- you would just want it to communicate there is a potential problem in the PATH variable?

    also 陈先生 (@ChenShiChao), is this a code suggestion or a fix for what rwijtvliet mentioned above?

  11. DI84 commented on Jun 24, 2025

    @DI84

    Had the same problem. Reinstallation of VSCode solved the issue. 🤷

    EDIT:
    Perhaps some further information is appropriate.

    I had the exact same problem as described by this Issue: When selecting "Debug Test" from the editor the debugger failed to start and a popup dialog with the message "Invalid message: Found duplicate in "env": PATH." was displayed.

    What did I try?:

    • I checked my environment variables (see here). Nothing out of the ordinary. => Did not help in my case.
    • Used older versions of the "Python" and "Python Debugger" extension (in various combinations) => Did not help at all.
    • Added the property "purpose" with the value "["debug-test"]" to my launch configuration (saw that here) => I could execute the debugger exactly once, then the same message reappeared. I had to restart VSCode in order to use the debugger again (once). Very weird, I know.

    What did help?:

    • I was frustrated because it seemed to work on my colleagues' computers, which had basically the same configuration. So I just installed VSCode again (did not even uninstall VSCode previously).
      => Works like a charm again (without any changes to my launch configuration).
  12. niko-la-petrovic commented on Jul 20, 2025

    @niko-la-petrovic

    Daniel (@DI84) I experienced the same issue under the same conditions. I'm about to attempt re-installing my VSC.
    Daniel (@DI84) no luck despite re-installing it.

    EDIT:
    I did have some duplicated path entries (both within the user and between the machine ones - courtesy of window's nmap or npcap tool I believe, I regret installingit) and some that ended with a slash.
    After deleting them the issue didn't go away. I also attempted to reinstall VSC but no luck.

    However the issue went away after rebooting. So do try that as well.

  13. github-actions commented on Aug 19, 2025

    @github-actions

    Hey Karthik Nadig (@karthiknadig), this issue might need further attention.

    Andreas Finkler (@DudeNr33), you can help us out by closing this issue if the problem no longer exists, or adding more information.

  14. DudeNr33 commented on Aug 21, 2025

    @DudeNr33
    Author

    I don't have access to the machine any more where this problem occurred, so I cannot really help any further here.
    Printing out the actual duplicated entries in the error messages (or some log) would probably help others who have this problem to fix it.

  15. github-actions commented on Sep 21, 2025

    @github-actions

    Hey Karthik Nadig (@karthiknadig), this issue might need further attention.

    Andreas Finkler (@DudeNr33), you can help us out by closing this issue if the problem no longer exists, or adding more information.

  16. martinthomas commented on Oct 19, 2025

    @martinthomas

    I had the same issue until I added "purpose" : "debug-test".
    If I comment out "type": "debugpy", I see the same problem.

  17. LarrxX commented on May 7, 2026

    @LarrxX

    Don't know if this is relevant, but I am having this issue when using a .env file in my settings.json. If I remove the file, test debugging works (but the rest of my project doesn't).

    Let me know if you need more info or if this is not the right place to comment about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugIssue identified by VS Code Team member as probable buggood first issueGood for newcomersneeds PRReady to be worked on

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions