Testing the Database Layer: typical problems & best practices
summary
Practical guide to testing the database layer for Python web apps: assumes you keep a real DB (does not mock it), recreates schema at test start, and enforces SQLAlchemy entity conventions (id, created/updated UTC timestamps, FK checks) via an entity base. Uses pytest, a wheelhouse for reproducible deps, and a lightweight testing_create factory system instead of brittle fixtures. Real-world scale: ~5,000 tests over 207 tables, ~24 minutes full run; introspection replaces many DB round trips and migrations are tested in phased steps.
AI-written summary · about
chapters (13)
- 0:00Intro
- 0:11Let's Talk
- 2:21Background & Assumptions
- 4:21Why Database Testing Is Hard
- 8:26Tests as Assets
- 11:38Easy Setup
- 12:04No Hassle Clone to Testing
- 14:45Consistency
- 16:57Idempotent: Test Prep
- 26:13Data Creation
- 38:53Patterns to Enforce
- 41:59Speed: As Fast as Reasonable
- 46:56Migration: Testing Workflow
related talks
27mDatabase Testing with pytest
28mThe Ultimate Python Database Toolkit: SQLAlchemy
35mTesting: Choose Your Weapons
34mLet's talk Databases in Python: SQLAlchemy and Alembic
01h 28mSQLAlchemy and You - Making SQL the Best Thing Since Sliced Bread
28mEgad! How Do We Start Writing Better Tests?
21mDon't just test, my friend, test better
30mFollow the Postgres brick road: a journey of testing against a real database server
