繁体   English   中英

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

[英]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.

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