Efficient FastAPI testing with pytest, dependency injection and snapshots
summary
Claim: using FastAPI dependency injection, pytest factory fixtures, and snapshot testing cuts maintenance and catches unintended API changes. Demonstration builds a simple to‑do API with both SQLite and an in‑memory repository, adds a required priority field and shows how hundreds of tests would break but require only a single factory change to fix. Uses a fixed UID provider so snapshots remain stable, runs faster when swapping in-memory repo, and the approach works in the demo.
AI-written summary · about
chapters (9)
- 0:00Introduction
- 1:11Purpose of automated testing
- 7:35Common testing problems
- 16:19Factory fixtures for tests
- 20:21Using snapshots in testing
- 21:45Dependency injection in FastAPI
- 27:11Implementing efficient tests
- 33:12Comparing test approaches
- 35:57Q&A
related talks
29mTesting asynchronous applications with FastAPI and pytest
41mTDD for APIs
28mDelivering successful API integrations
49mAn Easy Way to Automate Complex UI
26mQuickly Creating a Production-Ready API Using FastAPI and Docker…Explained with Memes
27mAPI development for data analysts/scientists with FastApi
24mGiven this, assert that: fluent testing using fixtures and properties
16mImprove application and code quality without overengineering
