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¶
- Project 3 (due Dec 05)
- Part A was due yesterday
- Part B due Thursday, 11/30
- Part C due Tuesday, 12/05
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:
- Thonny
- 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:
- Open your
PA3
folder in VSCode (not yourCS149
folder). - Open a Terminal and install the
pytest-cov
package:- Run the command
pip install pytest-cov
. - If
pip
doesn't work, trypip3
, orpython -m pip
, orpython3 -m pip
.
- Run the command
- Press F1 to open the Command Pallette.
- Type
work json
and press Enter.- This will create/open the file
.vscode/settings.json
in yourPA3
folder.
- This will create/open the file
- 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
- Save and close the
settings.json
file. - 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.