Lesson 4: Testing the shelf's rules with pytest
16 min read·14 Oct 2026
Module 10 · Lesson 4 · About 50 minutes · Needs: Module 6 (functions andassert), Module 7 Lessons 1, 2 and 4 (thebooknookpackage,dates.py,fees.py, installing pytest), Module 8 Lesson 1 (reading an error message)
The situation
Amira's request for this module is short: "Make sure it never breaks." The shelf's rules now live in booknook/fees.py and booknook/dates.py, and more people will touch them. One careless edit, a 25 where a 20 should be, and Ben is charged the wrong amount without anyone noticing.
This lesson writes tests: small programs that check the package against answers you already know. You will follow Ben's loan L13, The War of the Worlds, 9 days late on Wednesday 14 October 2026, which must cost 180 pence every time the tests run.