Talk

Efficient FastAPI testing with pytest, dependency injection and snapshots

LanguageEnglish
Audience levelIntermediate
Elevator pitch

Testing sucks. Especially when you have thousands of tests that are slow and painful to maintain. It doesn’t have to be that way. I’ll show you how to use FastAPI’s dependency injection, pytests factory fixtures, and snapshot testing to make your tests fast, readable, and easy to maintain.

Abstract

Introduction - 5min

We’ll discuss common testing problems:

  • tests that take forever to run
  • tests that need to be updated every time you change the implementation
  • tests that are hard to read

FastAPI application with inefficient tests - 10min

We’ll take a look at example FastAPI application that is tested with inefficient tests. We’ll take a look at what we need to do when we want to add a feature to our application - how many existing tests fail when we add a new feature, how many tests need updating when we add a new feature or refactor something, how long does it take to run the tests, …

FastAPI application with efficient tests - 25min We’ll take a look at the example FastAPI application that is tested with efficient tests. We’ll dig into pytest factory fixtures, FastAPI’s dependency injection for testing, snapshot testing, and testing doubles. We’ll compare the burden of adding a new feature to the application with inefficient tests.

Q & A - 5min I’ll answer questions from the audience

TagsBest Practice, Testing
Participant

Jan Giacomelli

I’m a Backend Lead @ Ren and CEO @ Giacosoft. I have worked with Python & AWS for the last 10 years. I’m a TDD practitioner. I’m always searching for better ways to deliver high-quality software at a rapid pace. I love simplicity. I write for testdriven.io. When I’m not programming I’m windsurfing, skiing, playing squash, hiking, …