Getting started with Testcontainers for Python
Table of contents
Learn how to create a Python application and test database interactions
using Testcontainers for Python with a real PostgreSQL instance.
Time to complete
15 minutes
In this guide, you will learn how to:
- Create a Python application that uses PostgreSQL to store customer data
- Use
psycopgto interact with the database - Write integration tests using
testcontainers-pythonandpytest - Manage container lifecycle with pytest fixtures
Prerequisites
- Python 3.10+
- pip
- A Docker environment supported by Testcontainers
NoteIf you're new to Testcontainers, visit the Testcontainers overview to learn more about Testcontainers and the benefits of using it.
Modules
- Create the project
Set up a Python project with a PostgreSQL-backed customer service.
- Write tests
Write integration tests using testcontainers-python and pytest with a real PostgreSQL database.
- Run tests
Run your Testcontainers-based integration tests and explore next steps.