2.2k stars · Apache-2.0 · 4.15.0 on PyPI (2026-07-24); GitHub's newest tag is testcontainers-v4.15.0 (2026-07-24) and a v4.15.0-rc4 candidate sits above it
Tests get a real, empty PostgreSQL started in a container and thrown away afterwards.
▶Repo detailsthe review · specs · pros & cons · install
What it is
Testcontainers for Python is a library you add to your test code. It starts real services inside Docker containers for the duration of a test run, hands your code the address to connect to, and removes them when the run ends.What it is good for. Anyone with a real database behind their app who has been putting off writing tests. The usual shortcut is to test against SQLite, a small file-based database, and hope it behaves like the real one. It does not, and the differences show up in production. Grasppy is FastAPI and PostgreSQL, so this is the piece that lets Claude Code write tests that actually prove something. It also sits neatly beside pglite from yesterday's edition: pglite gives a browser a Postgres engine with no server, and this gives a test run the real server in a throwaway container.
- Tests run against the same database engine as production, so a passing test means more.
- Each run starts empty, so tests cannot pollute each other or leave rubbish behind.
- It supports far more than databases. Redis, message queues and object storage all work the same way.
- Every test run pulls and starts containers, so the first run is slow and the rest add a few seconds each.
- It needs Docker available wherever the tests run, including on any build machine you use later.
- The latest release on GitHub is a release candidate, which is a version offered for testing. Install from PyPI, where 4.15.0 is the finished release.
cd ~/grasppy source venv/bin/activate pip install "testcontainers[postgres]" pytest