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
.
Once you have your launch configuration set, start your debug session with F5. Alternatively, you can run your configuration through the Command Palette (Ctrl+Shift+P) by filtering on Debug: Select and Start Debugging or typing 'debug ' and selecting the configuration you want to debug.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With