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
Solution 1:
If you're on a Mac or Linux, the following launch config should work for a single unit test executed by Django:
    {
        "name": "Python: Django Debug Single Test",
        "type": "python",
        "request": "launch",
        "program": "${workspaceFolder}/manage.py",
        "args": [
            "test",
            "`echo -n ${relativeFileDirname} | tr \/ .`.${fileBasenameNoExtension}"
        ],
        "django": true
    },
This uses the tr command to translate / into . in the relative path.
Solution 2:
There is no translation of file path to dotted name, so you will need to hard-code that in your launch.json.
Solution 3:
If you're using Windows and the git bash, the launch config with tr will also work, but you'll need to quote the variable substitution and quote the double backslashes.
    {
        "name": "Python: Django Debug Single Test",
        "type": "python",
        "request": "launch",
        "program": "${workspaceFolder}/manage.py",
        "args": [
            "test",
            "`echo -n \"${relativeFileDirname}\" | tr \\\\ .`.${fileBasenameNoExtension}"
        ],
        "django": true
    },
Post a Comment for "How Do I Debug Individual Django Tests In Vscode?"