# Testing with a Real, Throwaway Database

API tests that touch a database get a fresh SQLite file in pytest's tmp_path for every test, with the migrations run and a few rows added in a fixture, and app.dependency_overrides swaps get_db for one that opens that file, so the tests run real SQL without ever touching the real data.

![Cheat sheet: Testing with a Real, Throwaway Database](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/15c5dea38431400ca1d2e052b7a5a50b.webp)

- Category: FastAPI
- Level: Journeyman
- Tags: Dependency Override, fastapi, Integration Test, Mock, rest-api, Test Fixture (python), tmp_path
- Author: Gregor Dzierzon
- Updated: November 23, 2026

Source: https://www.ask-codey.com/cheat-sheets/fastapi-data-testing-real-database-cheat-sheet
