0PricingLogin
Flask Academy · Lesson

Isolate Tests with a Test Database

Use a throwaway DB per test run.

Why Isolate the Database

Tests must never touch your real data. A test database keeps every run clean, so one test can never corrupt another or your production rows.

Use a Throwaway SQLite DB

The easy choice is an in-memory SQLite database. It lives only in RAM and vanishes the moment the test process ends.

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'

All lessons in this course

  1. The Test Client and Fixtures
  2. Assert on Routes and JSON
  3. Isolate Tests with a Test Database
  4. Test Authenticated Endpoints
← Back to Flask Academy