Unit testing¶
Tests are how you find out whether your code does what you think it does — and, more usefully, whether it still does the right thing six months later when you change something nearby. Python's standard unittest module covers the ground for almost everything you'll write at this stage. This guide gets you from your first test to fixtures and exception testing.
Start here¶
If unittest is new to you, work through the Learn section in order — four short notebooks, around fifteen minutes each. Every code cell can be edited and run in place, directly on the page; no install required.
If you already know the basics and are looking for a specific technique, jump to the Recipes section, or scan the Reference for the API and conventions.
What this guide covers¶
Learn — your first test, testing thoroughly, best practices, and fixtures.
Recipes — running tests in Jupyter, testing exceptions, and the mistakes worth avoiding.
Reference — the unittest API, the assertion methods, and naming conventions.
Concepts — why unit testing pays off, and how a well-shaped test is structured.