vscode-python: Error: spawn ENOENT on test discovery when `"python.testing.cwd"` is set

I have searched stackoverflow as well as GitHub issues here and found some related issues but nothing conclusive or helpful.

Environment data

  • VS Code version: 1.54.3
  • Extension version (available under the Extensions sidebar): v2021.3.658691958
  • OS and version: macOS Big Sur 11.2.3
  • Python version (& distribution if applicable, e.g. Anaconda): all
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): n/a
  • Relevant/affected Python packages and their versions: pytest | unittest
  • Relevant/affected Python-related VS Code extensions and their versions: vscode-python v2021.3.658691958
  • Value of the python.languageServer setting: pylance

Expected behaviour

python process for test discovery would spawn successfully or produce more descriptive error.

Actual behaviour

python /Users/patrick/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /Users/patrick/dev/vscode-test -s --cache-clear
Test Discovery failed: 
Error: spawn /Users/patrick/.pyenv/shims/python ENOENT

Steps to reproduce:

  1. Delete/move ~/.vscode for fresh vscode user env.
  2. Create simple python project with one pytest test and open vscode to folder with only the python extension and pytest auto discovery enabled.
  3. Observe output in Python Test Log listed below.
  4. Copy/paste command line from Python Test Log into macOS terminal.
  5. Observe process runs successfully and discovers pytest test.

*NOTE: I am unable to reproduce this problem on a clean system. But, it occurs for any python 3 version installed via system, brew, and pyenv regardless of whether the vscode project points to a symlink or executable.

Logs

Output for Python in the Output panel

User belongs to experiment group 'pythonaacf'
User belongs to experiment group 'pythonSendEntireLineToREPL'
User belongs to experiment group 'pythonNotDisplayLinterPrompt'
User belongs to experiment group 'pythonTensorboardExperiment'
User belongs to experiment group 'ShowExtensionSurveyPrompt - enabled'
User belongs to experiment group 'CollectLSRequestTiming - control'
> conda --version
> conda info --json
> pyenv root
> python3.7 ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> ~/.pyenv/shims/python ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> pyenv root
> pyenv root
> pyenv root
> pyenv root
> pyenv root
> pyenv root
Starting Pylance language server.
Python interpreter path: ~/.pyenv/shims/python
> ~/.pyenv/shims/python ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/dev/vscode-test -s --cache-clear
cwd: api
> ~/.pyenv/shims/python ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/dev/vscode-test -s --cache-clear
cwd: api
Error 2021-03-20 20:11:59: Failed to parse discovered Test [Error: spawn /Users/patrick/.pyenv/shims/python ENOENT
	at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
	at onErrorNT (internal/child_process.js:469:16)
	at processTicksAndRejections (internal/process/task_queues.js:84:21)] {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn /Users/patrick/.pyenv/shims/python',
  path: '/Users/patrick/.pyenv/shims/python',
  spawnargs: [
    '/Users/patrick/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/testing_tools/run_adapter.py',
    'discover',
    'pytest',
    '--',
    '--rootdir',
    '/Users/patrick/dev/vscode-test',
    '-s',
    '--cache-clear'
  ]
}
> conda --version
> ~/.pyenv/shims/python ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/pyvsc-run-isolated.py -c "import pytest"
> ~/.pyenv/shims/python ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/pyvsc-run-isolated.py -c "import pytest"
Error 2021-03-20 20:12:00: Python Extension: displayDiscoverStatus [TypeError: Cannot read property 'uri' of undefined
	at /Users/patrick/.vscode/extensions/ms-python.python-2021.3.658691958/out/client/extension.js:9:495273]

Output for Python Test Log in the Output panel

python /Users/patrick/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /Users/patrick/dev/vscode-test -s --cache-clear
Test Discovery failed: 
Error: spawn /Users/patrick/.pyenv/shims/python ENOENT

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 22

Most upvoted comments

Note you’ll need to Reload for changes in the setting to take affect, the cwd in python output panel doesn’t change unless we reload. Does removing the setting and reloading make a difference? For me it does fix the spawn enoet issue.

Ah, that’s right. Reloading the window did fix the spawn problem on both projects.

I have no idea where ${workspaceDir} came from, it isn’t anywhere in my project folder or the extensions folder. Though it did appear when I removed the "python.testing.cwd" from my settings. It looks like the extension always prints cwd <whatver-it-is-set-to> on a new line.

And - setting it to ${workspaceFolder}/api did fix the cwd problem! Good grief…cheers for the help!