Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio code 如何使用环境变量为pytest配置VS代码_Visual Studio Code_Vscode Settings_Vscode Debugger - Fatal编程技术网

Visual studio code 如何使用环境变量为pytest配置VS代码

Visual studio code 如何使用环境变量为pytest配置VS代码,visual-studio-code,vscode-settings,vscode-debugger,Visual Studio Code,Vscode Settings,Vscode Debugger,我正在尝试调试pytest。我想注入一个环境变量。下面是我如何设置launch.json的 { "type": "python", "request": "test", "name": "pytest", "console": "integratedTerminal", "env"

我正在尝试调试pytest。我想注入一个环境变量。下面是我如何设置launch.json的

{
    "type": "python",
    "request": "test",
    "name": "pytest",
    "console": "integratedTerminal",
    "env": {
        "ENV_VAR":"RandomStuff"
    }
},
但是当我开始调试的时候。我没有看到env变量被注入,因此我的测试预期env变量失败

我也注意到了错误

Could not load unit test config from launch.json

无法真正了解如何使用Vscode修复“单元”测试调试。但是有了Pytest,可以调用类似于
python-mpytest
() 这意味着Vscode可以像模块一样配置

"configurations": [
        {
            "name": "Python: Module",
            "type": "python",
            "request": "launch",
            "module": "pytest",
            "args": ["--headful","--capture=no", "--html=report.html"],
        }
这足以调试python测试。然后还可以插入环境变量

   "env": {
        "ENV_VAR":"RandomStuff"
    }

这很奇怪,在这里发布您使用变量的代码片段。您在哪里添加最后的
env
部分?您可以将其附加到配置中。例如,在上面的示例中,如果您希望它位于所有键的末尾,它可以在“args”后面,例如“配置”:[{“name”:“Python:Module”,“type”:“Python”,“request”:“launch”,“Module”:“pytest”,“args”:[--headful”,“--capture=no”,“--html=report.html”],“env”:{“ENV_VAR”:“RandomStuff”}