VS Code has a built-in Test Explorer that makes running tests super easy!
-
Find the Test Explorer icon in the left sidebar (it looks like a flask/beaker π§ͺ)
- Or use the keyboard shortcut:
Ctrl+Shift+T(Windows/Linux) orCmd+Shift+T(Mac)
- Or use the keyboard shortcut:
-
See all your tests organized by set:
π course π set1 β test_set1_exercise1.py β test_set1_git_setup.py π set2 β test_set2_exercise0.py β test_set2_exercise2.py ... -
Run tests - Click the play button (βΆ) next to:
- A single test to run just that one test
- A test file to run all tests in that file
- A set folder to run all tests for that week
- The top-level folder to run ALL tests
-
See results inline:
- β Green checkmark = test passed
- β Red X = test failed
- Click on a failed test to see why it failed
-
Debug tests - Click the debug icon (π) next to any test to run it with breakpoints
- Tests automatically refresh when you save your code
- You can run tests while editing - no need to switch to the terminal
- Failed tests show you exactly what went wrong
- Green checkmarks are very satisfying! π
If you prefer the terminal (or the Test Explorer isn't working):
# Run all tests for a specific set
pytest ../course/set1/
# Run a specific test file
pytest ../course/set2/test_set2_exercise0.py
# Run with more detail
pytest ../course/set1/ -v
# Stop at the first failure
pytest ../course/set1/ -x- If tests aren't showing up, try:
Developer: Reload Windowfrom the Command Palette (Ctrl+Shift+P) - Make sure you've opened the
mefolder as your workspace (not the parent folder) - Check that the Python extension is installed and active
Happy testing! π