Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode on discover tests Error: spawn python ENOENT

I am running a python project in vscode with virtualenv. Python interpreter is set right. When I'm trying to discover tests it gives me an error saying

python /Users/user/.vscode/extensions/ms-python.python-2019.10.44104/pythonFiles/testing_tools/run_adapter.py discover pytest -- -s project/
Test Discovery failed: 
Error: spawn /Users/<username>/apps/project/venv/bin/python ENOENT

My vscode settings.json looks something like this and I haven't configured launch.json

{
    "python.pythonPath": "/Users/<username>/apps/project/venv/bin/python",
    "python.testing.unittestEnabled": false,
    "python.testing.nosetestsEnabled": false,
    "python.testing.pytestEnabled": true,
    "python.testing.pytestArgs": [
        "project"
    ],
}

When I just type /Users/<username>/apps/project/venv/bin/python on terminal python shell opens up.

ENOENT Generally means that it's an invalid path, but the path seems perfectly fine.

$echo $PATH
/Users/<username>/apps/project/venv/bin
like image 690
Bhavani Ravi Avatar asked Nov 11 '19 10:11

Bhavani Ravi


3 Answers

I just ran into the same issue and found that it was due to a non-existing folder in the python.testing.cwd setting where I used workspaceDir instead of workspaceFolder as a variable

Note that it seems to require restarting VSCode before a change here has any effect, i.e. if you change it to the wrong value it will seemingly continue to work but after a restart you'll get ENOENT and vice-versa

like image 72
Flamefire Avatar answered Nov 20 '22 05:11

Flamefire


It resolved itself after I deleted the local .vscode folder inside the project, saved the workspace, and created a new .vscode/settings.json containing the testing settings. That seems to have fixed it.

Source: https://github.com/microsoft/vscode-python/issues/5316

like image 4
Agnel Vishal Avatar answered Nov 20 '22 06:11

Agnel Vishal


Adding "python.testing.cwd": "${workspaceFolder}" to settings.json solved the issue for me.

like image 4
user7005976 Avatar answered Nov 20 '22 05:11

user7005976