Skip to content

Error: spawn <python interpreter> ENOENT on test discovery when "python.testing.cwd" is set #15739

@patrickkidd

Description

@patrickkidd

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

Metadata

Metadata

Assignees

Labels

area-testingbugIssue identified by VS Code Team member as probable buginfo-neededIssue requires more information from posterinvestigatingWe are looking into the cause of the issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions