![](/img/trans.png)
[英]How to debug a file from current directory with Python in VS Code?
[英]How to debug the current python test file with pytest in VS Code
我知道如何配置VS Code调试器的launch.json
来调试当前的 python 文件:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${fileDirname}",
"env": {
"PYTHONPATH": "${workspaceFolder}${pathSeparator}${env:PYTHONPATH}"
}
},
}
但是如何配置launch.json
来调试当前的python测试文件与pytest
?
在 Django 和 Pytest 的上下文中,这对我有用:
{
"name": "Python: Debug test file",
"type": "python",
"request": "launch",
"module": "pytest",
"args": [
"${file}"
],
"django": true
}
在您的 launch.json 文件中添加以下配置,它应该可以工作。
"configurations": [
{
"name": "Python: Pytest",
"type": "python",
"request": "launch",
"module": "pytest",
"args": [
"${file}"
],
},
]
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"module": "pytest",
"console": "integratedTerminal",
"args" : ["-s", "-q", "-m <id inpytest.ini>", "-myArgu1=xxx"]
}]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.