Oct 13: Using Visual Studio Code
Learning Objectives
After today's class, you should be able to:
- Use VS Code to run, debug, and auto-format Python programs.
- Identify at least three keyboard shortcuts specific to VS Code.
- Describe how to run pytest in VS Code (from multiple locations).
Announcements¶
Due tomorrow:
VS Code Tutorial¶
[30 min]
- If you are absent today, complete this tutorial on your own
- Bring your completed VS Code setup to class on Wednesday
Lecture / Demo¶
[20 min]
Editing¶
- Keyboard shortcuts to know:
- Command Palette F1
- Rename Symbol F2
- Go to Definition F12
- See also Keyboard Shortcuts
Testing¶
You can run pytest automatically in VS Code!
- Click "Testing" (bottom icon) on the Activity Bar (left sidebar).
- Now you can click the "" buttons to run pytest at any level.
- You can also "Debug Test" and "Run Test with Coverage".
Note: Over time, extra folders like __pycache__ and .pytest_cache will be created automatically.
These folders are automatically hidden by your .vscode/settings.json file.
Exercise
- Set a breakpoint in
triangles.py. - Right-click a in
test_triangles.py. - Click "Debug Test" in the context menu.
- Step through the code with the debugger.