Ship It: Testing, Git & Sharing Your Apps / Make it solid
Lesson 2 of 10
Your first test
pytest finds files named test_*.py and runs every function starting with test_. Use assert to check results.
Key points
- test_ functions in test_ files
- assert checks a condition
- Run with: pytest
# passwords.py
def score(pw):
return 0 if pw == "password" else len(pw)
# test_passwords.py
from passwords import score
def test_common_password_scores_zero():
assert score("password") == 0
def test_longer_scores_more():
assert score("abcdefghij") > score("abc")Your turn
Write three tests for your password checker from App 3 and run pytest.
Quiz · +10 XP
How does pytest find tests?
Log in to save progress and earn XP.