Skip to content

Nov 29: Quiz 6a, Project Hints

Learning Objectives

After today's class, you should be able to:

  • Write unit tests for all functions in PA3.
  • Run pytest with code coverage in VSCode.

Reminders

Testing PA3

  • "Schedule" vs "Catalog"
  • JSON vs actual format
  • Tests that are provided
  • How your tests are graded

Quiz 6a

  • Log in as student
  • Only two windows:
    1. Thonny
    2. Web browser
  • Web traffic monitored
  • Log out when finished

VSCode Setup

Reminder

If you haven't already, please work through the Visual Studio Code Setup instructions. Let us know if VSCode isn't working on your computer. VSCode has a lot of advantages for working on a project like PA3.

Follow these steps to configure pytest to run with code coverage:

  1. Open your PA3 folder in VSCode (not your CS149 folder).
  2. Open a Terminal and install the pytest-cov package:
    • Run the command pip install pytest-cov.
    • If pip doesn't work, try pip3, or python -m pip, or python3 -m pip.
  3. Press F1 to open the Command Pallette.
  4. Type work json and press Enter.
    • This will create/open the file .vscode/settings.json in your PA3 folder.
  5. Paste the following settings between the curly braces:
        "python.testing.pytestArgs": [
            "--cov=.",
            "--cov-branch",
            "--cov-report=term",
            "--cov-report=xml"
        ],
        "python.testing.pytestEnabled": true,
        "coverage-gutters.showGutterCoverage": false,
        "coverage-gutters.showLineCoverage": true
    
  6. Save and close the settings.json file.
  7. Install the Coverage Gutters extension:
    • Click the "Extensions" icon on the left sidebar
    • Search for "Coverage Gutters" (by ryanluker)

To view coverage results, click the "Watch" button on the bottom left of VSCode.