Skip to content

Recipes: Unit testing

Short, task-focused how-tos for the testing jobs that come up over and over. Each recipe assumes you can already write a basic TestCase — if a piece of the API surprises you, the Learn section is one click away.

Unlike the tutorials, the recipes don't have a recommended order. Pick whichever is useful right now.

Recipes in this guide

  • Run tests in Jupyter — how to drive unittest from inside a notebook, including the small workarounds you'll need.
  • Test exceptionsassertRaises, checking the message, and the patterns for asserting on raised errors.
  • Avoid common testing mistakes — over-mocked tests, brittle assertions, and the habits that turn a test suite into a liability.