Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug the current python test file with pytest in VS Code

I know how to configure the VS Code debugger's launch.json to debug the current python file:

{ 
    "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}"
            }
        },
}

But How to configure launch.json to debug the current python test file with pytest?

like image 283
gustavz Avatar asked Aug 25 '26 22:08

gustavz


1 Answers

This is what works for me in the context of Django and Pytest:

{
  "name": "Python: Debug test file",
  "type": "python",
  "request": "launch",
  "module": "pytest",
  "args": [
    "${file}"
  ],
  "django": true
}
like image 186
JSEvgeny Avatar answered Aug 27 '26 14:08

JSEvgeny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!