如何在 VS Code 中使用 pytest 调试当前的 python 测试文件

gus*_*avz 6 python debugging pytest visual-studio-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}"
            }
        },
}
Run Code Online (Sandbox Code Playgroud)

但是如何配置launch.json来调试当前的 python测试文件pytest

JSE*_*eny 15

这就是在 Django 和 Pytest 的上下文中对我有用的内容:

{
  "name": "Python: Debug test file",
  "type": "python",
  "request": "launch",
  "module": "pytest",
  "args": [
    "${file}"
  ],
  "django": true
}
Run Code Online (Sandbox Code Playgroud)


小智 -1

{ 
    "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"]            
            
        }]
}
Run Code Online (Sandbox Code Playgroud)