Section 3 VS Code debugger for graphical step-through
Some bugs read better in a GUI. The VS Code debugger renders the call stack, locals, and a
watch panel in three side-by-side columns. Set up the Python extension first (covered in Python Dev Setup for University Coursework).
Set a breakpoint with one click
Click the gutter to the left of any line number. A red dot appears. Press F5. VS Code
prompts for a debug configuration; pick Python File. Execution stops on
the red-dot line. The left sidebar fills with five panels: Variables, Watch, Call Stack, Breakpoints, and Loaded Scripts.
The top toolbar gives the same controls as pdb in icon form: Continue (F5),
Step Over (F10, equivalent to pdb n), Step Into (F11, equivalent to pdb s), Step Out (Shift+F11),
Restart, Stop.
.vscode/launch.json for running with arguments
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
},
{
"name": "Python: Current File with args",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"args": ["--input", "data/grades.csv", "--drop", "2"],
"console": "integratedTerminal",
"justMyCode": true
},
{
"name": "Python: pytest",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"args": ["-v", "tests/"],
"console": "integratedTerminal",
"justMyCode": false
}
]
}
The first config debugs whichever .py file is open. The second
feeds command-line arguments to the same file. The third runs pytest under the debugger so you can step into a failing test. justMyCode: false lets you step into pandas, sklearn, or any library you imported; set it to true to stay inside your own files.