Skip to content

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:

  • Reading Week 8
  • Part A of PA 1
  • No reflection until after Part B

VS Code Tutorial

[30 min]

Visual Studio Code Setup

  • 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!

  1. Click "Testing" (bottom icon) on the Activity Bar (left sidebar).
  2. 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

  1. Set a breakpoint in triangles.py.
  2. Right-click a in test_triangles.py.
  3. Click "Debug Test" in the context menu.
  4. Step through the code with the debugger.