Integration tests with a real database: Docker + pytest

12 steps · about 5 h 32 min · Intermediate

  1. The Practical Test Pyramid (article, Martin Fowler / Ham Vocke, 40 min)

    Start with the idea: what an integration test is, why a database test belongs in that layer, and how it differs from a unit test.

  2. Software Testing Guide (article, Martin Fowler, 20 min)

    This clears up the confusing terms (narrow vs broad integration tests) before you start writing them.

  3. What is a container? (guide, Docker Docs, 12 min)

    Containers and images are the mechanism that gives each test run a disposable database, so learn them first.

  4. Run your first container (guide, Docker Docs, 20 min)

    Hands-on practice with docker run, ps and logs, and with what happens to data when a container is removed.

  5. Overview of the Docker workshop (tutorial, Docker Docs, 45 min)

    It covers Docker Compose with a database container, which shows the manual setup that Testcontainers later automates.

  6. How to use fixtures (doc, pytest docs, 40 min)

    Fixtures, yield teardown, scopes and conftest.py are the pytest tools that control the container's lifecycle.

  7. Getting started with Testcontainers for Python (tutorial, Testcontainers, 30 min)

    The official walkthrough builds your first pytest suite against a real Postgres container, with a module-scoped container and a clean table before each test.

  8. Test-Driven Development with Python, Testcontainers, and pytest (article, Collabnix, 25 min)

    A second, test-first project that reinforces the same pattern with finalizers and a customers table.

  9. Testcontainers: PostgreSQL, Redis, Kafka Testing (article, Botmonster, 25 min)

    It adds Alembic migrations in the fixture and per-test isolation using transaction rollback with savepoints.

  10. Testcontainers Python: pytest + Docker Integration Testing (2026) (article, HelpMeTest, 25 min)

    It compares fixture scopes (session vs function) and autouse cleanup, so you can trade speed against isolation.

  11. Testcontainers Python Pytest — Integration Testing Guide 2026 (article, QASkills, 35 min)

    It goes further with SQLAlchemy sessions, async drivers, container reuse and CI configuration.

  12. Container Testing with Testcontainers - pytest-test-categories (article, pytest-test-categories docs, 15 min)

    Last, it covers marking container tests as slower tests and skipping them cleanly when Docker isn't available, for a robust suite.