13

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
Bhavani Ravi
  • 2,130
  • 3
  • 18
  • 41

6 Answers6

9

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

user7005976
  • 345
  • 2
  • 5
7

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

Flamefire
  • 5,313
  • 3
  • 35
  • 70
  • 4
    Removed the `pytest.testing.cwd` and reloaded VSCode and it cleared my issue up as well - thanks this suggestion worked great! Looks like VScode settings can get cached even when they appear to be updated. – William Jan 21 '21 at 15:15
  • Thank you for this. I was trying to resolve this on my own, though I didn't know one has to restart/reload vscode/theia as other settings take effects immediately. – Petr Szturc Feb 22 '21 at 10:59
4

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

Agnel Vishal
  • 564
  • 6
  • 13
2

Still don't know what the exact issue is but, I deleted every trace of vscode from my laptop. On reinstalling it from the scratch it worked.

Bhavani Ravi
  • 2,130
  • 3
  • 18
  • 41
0

I had the same issue and resolved it by making sure that all settings.json files (user, workspace, and potentially docker container) had been cleared of python.testing.* entries.

Jason Lee
  • 1
  • 1
0

I am using Azure Function project. For me solution was adding those rows to setting.json

{
    "python.defaultInterpreterPath": ".venv",
    "azureFunctions.deploySubpath": ".",
    "azureFunctions.scmDoBuildDuringDeployment": true,
    "azureFunctions.pythonVenv": ".venv",
    "azureFunctions.projectLanguage": "Python",
    "azureFunctions.projectRuntime": "~3",
    "debug.internalConsoleOptions": "neverOpen",
    "python.testing.pytestArgs": [
        "tests"
    ],
    "python.testing.unittestEnabled": true,
    "python.testing.pytestEnabled": true,
    "python.testing.autoTestDiscoverOnSaveEnabled": true,
    "python.testing.cwd": "${workspaceFolder}"
}
Alex
  • 114
  • 5