Test-Driven Development with Python, Flask, and Docker

Learn how to build, test, and deploy a production-grade microservice powered by Python, Flask, and Docker!

"Code without tests is broken by design." - Jacob Kaplan-Moss

Learning Objectives

By the end of this course, you will be able to:

  1. Develop a RESTful API with Python, Flask, and Flask-RESTX
  2. Practice Test-Driven Development
  3. Test a Flask app with pytest
  4. Containerize Flask and Postgres inside a Docker container
  5. Run unit and integration tests with code coverage inside a Docker container
  6. Check your code for any code quality issues via a linter
  7. Configure GitLab CI for continuous integration and deployment
  8. Speed up a Docker-based CI build with Docker Cache
  9. Deploy Flask, Gunicorn, and Postgres to Heroku with Docker
  10. Parameterize test functions and mock functionality in tests with pytest
  11. Run tests in parallel with pytest-xdist
  12. Configure Flask-Admin with SQLAlchemy models
  13. Document a RESTful API with Swagger/OpenAPI

Tools and Technologies


  1. Python
  2. Flask
  3. Docker
  4. Postgres


  1. Flask-RESTX
  2. Flask-SQLAlchemy
  3. Gunicorn
  4. Swagger/OpenAPI
  5. Flask-Admin

Testing and Linting

  1. pytest
  2. Coverage.py
  3. Flake8
  4. Black
  5. isort
  6. HTTPie


  1. GitLab
  2. Heroku

flask tdd logo


This is not a beginner course. It's designed for the advanced-beginner -- someone with at least six months of web development experience. Before beginning, you should have some familiarity with the following topics. Refer to these resources for more info:

Topic Resource
Docker Get started with Docker
Docker Compose Get started with Docker Compose
Flask Flaskr TDD, Developing Web Applications with Python and Flask



  • Current version: 3.1.0
  • Last updated: November 25th, 2020
  • AuthorMichael Herman

What will you learn?

Part 1

In this first part, you'll learn how to develop a RESTful API with Python, the Flask web framework, Flask-RESTX, and Postgres. You'll containerize Flask and Postgres to run inside Docker containers and configure pytest in order to practice Test-Driven Development (TDD).

Part 2

In the second part, you'll start by deploying Flask, Gunicorn, and Postgres to Heroku with Docker. You'll then continue building out the RESTful API as you write unit and integration tests. Finally, we'll look at how to document the API with Swagger.

Table of Contents

Table of contents from Test-Driven Development with Python, Flask, and Docker:

Part 1
Part 2
  • Deployment
  • Code Coverage and Quality
  • Continuous Integration
  • Continuous Delivery
  • Remaining Routes
  • Pytest Monkeypatching
  • Advanced CI
  • Flask Admin
  • API Documentation
  • Workflow
  • Structure
  • Next Steps

Get the full course:

Join our mailing list to be notified about course updates and new tutorials.