Search code examples
pythondjangovisual-studio-codevscode-debugger

How do I debug individual Django tests in vscode?


I added a launch configuration that allows me to run all tests in Django and another that allows me to run the server, both of these work fine.

I am looking for a way to debug an individual file, but using ${file} in the arguments gives a normal path which django doesn't like.

I want a way to change ${file} into a python path so that I can debug my tests on a single file.

python manage.py test --noinput --keepdb python.path.to.my.file

works in the command line.

The following configuration seems to be almost right:

      {   "name": "Test File",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "args": [
                "test",
                "--noinput",
                "--keepdb",
                "${file}"
            ],
            "django": true
        }

However, when I run this configuration I get an error, which I think is because ${file} turns into

path/to/my/file instead of path.to.my.file.


Solution

  • There is no translation of file path to dotted name, so you will need to hard-code that in your launch.json.