Concept
pytest finds functions named test_* and runs them, reporting each failing assert with the values involved. A test is a plain function with an assert in it, which keeps the barrier to writing one low.
The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.
A few lines that show Writing tests with pytest doing its job.
# test_slugify.py
from slugify import slugify
import pytest
def test_lowercases_and_joins_with_dashes():
assert slugify("Hello World") == "hello-world"
@pytest.mark.parametrize("raw", ["", " ", "!!!"])
def test_rejects_empty_input(raw):
with pytest.raises(ValueError):
slugify(raw)Writing one test that checks everything. When it fails you do not know which behaviour broke. One behaviour per test, named after what it checks.
Your roadmap puts these before Writing tests with pytest, unless you already know them.
Once a session shows you understand Writing tests with pytest, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.
Topics that build on Writing tests with pytest.