Lab: Test and protect the shelf's code
27 min read·14 Oct 2026
Module 10 · Lab · About 60 minutes · Needs: lessons 1 to 4 of this module, and the Module 9 lab (thebooknookfolder in your Drive, withmodels.py)
What you are building
Amira's request for this module is "Make sure it never breaks." The four lessons gave you the tools: generators (Lesson 1), decorators (Lesson 2), context managers (Lesson 3) and pytest (Lesson 4).
This lab puts all four into the project. A new module, booknook/tools.py, holds a generator of overdue loans, a log_calls decorator applied to Library.lend and Library.return_book, and a safe_save context manager. A new folder, tests/, holds four test files that check every rule, edge cases included. Then pytest runs them and mypy checks the package's hints.
Open a new Colab notebook, call it module-10-lab.ipynb, and run each cell in order.