Capstone: a test suite that catches bugs

P30.pytest-foundations.04 · Audience: guest, it-ml, language-pro · Prerequisites: Coverage as a signal, not a goal

Real LLM grading for this pageLLM grading (this page):

The pillar's finale turns the tables. Every rung so far graded whether your code was right; this one grades whether your tests are. You are handed an untested Cart and write a suite good enough to trust - and the capstone proves it the only honest way: by running your suite against a correct Cart and several broken ones, and checking it passes the first and fails the rest.

Step 1 / 4The Cart under test
ⓘ Concept: A small contract with real edges
Cart has three methods: add(name, price, qty=1) appends an item and raises on qty <= 0 or price < 0; subtotal() sums price * qty (0 when empty); total(discount=0.0) returns subtotal * (1 - discount) and raises when discount is outside [0, 1]. Each of those behaviours is something a test can pin.

Why it matters — Every method has a happy path and a guard; a suite that only walks the happy path is exactly the kind this capstone is built to catch.

Ask the mentor about this module

Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.

Ctrl/Cmd + Enter to send

🎓 Practice ladder

1 graded rung · ~30 min

Your turn: write check(Cart) - a suite that accepts a correct cart and catches every injected bug.

Capstone - a test suite that catches bugs (project)

Loading exercise…

Writing code that passes tests is one skill; writing tests that fail when the code is wrong is the one that keeps a system honest. That is the whole pillar, in one rung.