简体   繁体   English

VSCode 发现测试错误:spawn python ENOENT

[英]VSCode on discover tests Error: spawn python ENOENT

I am running a python project in vscode with virtualenv .我正在使用virtualenv在 vscode 中运行 python 项目。 Python interpreter is set right. Python 解释器设置正确。 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我的 vscode 设置。json 看起来像这样,我还没有配置启动。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.当我在终端 python shell 上键入/Users/<username>/apps/project/venv/bin/python时,就会打开。

ENOENT Generally means that it's an invalid path, but the path seems perfectly fine. ENOENT 通常意味着它是一个无效的路径,但路径看起来非常好。

$echo $PATH
/Users/<username>/apps/project/venv/bin

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我刚刚遇到了同样的问题,发现这是由于python.testing.cwd设置中不存在的文件夹,我使用workspaceDir而不是workspaceFolder作为变量

Note that it seems to require restarting VSCode before a change here has any effect, ie 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请注意,这里的更改似乎需要重新启动 VSCode,即如果您将其更改为错误的值,它似乎会继续工作,但在重新启动后您将获得 ENOENT,反之亦然

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.在我删除项目中的 local.vscode 文件夹、保存工作区并创建一个包含测试设置的 new.vscode/settings.json 后,它自行解决了。 That seems to have fixed it.这似乎已经解决了它。

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

Adding "python.testing.cwd": "${workspaceFolder}" to settings.json solved the issue for me."python.testing.cwd": "${workspaceFolder}"添加到settings.json为我解决了这个问题。

Still don't know what the exact issue is but, I deleted every trace of vscode from my laptop.仍然不知道确切的问题是什么,但是,我从笔记本电脑上删除了所有 vscode 痕迹。 On reinstalling it from the scratch it worked.从头开始重新安装它就可以了。

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.我遇到了同样的问题,并通过确保所有 settings.json 文件(用户、工作区和可能的 docker 容器)已清除 python.testing.* 条目来解决它。

I am using Azure Function project.我正在使用 Azure Function 项目。 For me solution was adding those rows to setting.json对我来说,解决方案是将这些行添加到 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}"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM