我使用Visual Studio代码编辑我的Behave场景和Python步骤。
我已经能够使用Visual Studio代码控制台运行我的步骤。
我无法配置python调试器来调试我的Python脚本,当它们被behave调用时。
如何在Behave.exe中使用Visual Studio Code Python调试器?什么是调试配置参数?qazxsw poi
添加配置以启动debugin当前功能:
visual studio code launch.json
最后,我成功通过使用以下Launch.json调用Python的行为来调试我的python代码:
{
"name": "Python: Behave current file",
"type": "python",
"request": "launch",
"module": "behave",
"console": "integratedTerminal",
"args": [
"${file}"
]
},
我能看到的唯一不同的是你和我的 {
"name": "Python: Terminal (integrated)",
"type": "python",
"request": "launch",
"program": "C:\\Program Files\\Python37\\Lib\\site-packages\\behave\\__main__.py",
"console": "integratedTerminal",
"cwd":"${workspaceFolder}\\Drivers_Features"
},
设置是我使用launch.json
设置测试目录而不是切换args
:
cwd
我使用带有pip的%path%安装了行为的conda环境。
在我的环境中,我还有一个tests /子目录,我在执行行为之前明确使用cwd来改变路径。
这是我的launch.json的摘录
{
"name": "Python: Behave (.venv)",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/.venv/bin/behave",
"console": "integratedTerminal",
"args": [
"tests/integration"
],
}
我在这里有效地尝试实现的是类似于命令行上的以下步骤:
{
"name": "Python: Behave",
"type": "python",
"request": "launch",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}/tests",
"args": ["-m", "behave"]
},
cwd /path/to/workspace/folder/tests
我安装了VSCode for Python扩展,它可以识别我的conda虚拟环境。
我也在Windows机器上运行它,因此您的里程可能会因Linux或Mac而异。
您也可以使用此配置
python -mbehave
{
"name": "Behave",
"type": "python",
"request": "launch",
"module": "behave",
"cwd": "${workspaceRoot}/behave"
}
我喜欢 {
"name": "Python: Behave",
"type": "python",
"request": "launch",
"module": "behave",
"console": "integratedTerminal",
"args": [
"${file}",
"-n",
"${selectedText}",
]
}
的答案,因为它不需要更改当前的工作目录。
对于其他Windows用户(因为用户问的问题是),行为.exe程序位于“Scripts”文件夹中:
lindstromhenrik