Python library for throwaway instances of anything that can run in a Docker container
Project description
Testcontainers Python
testcontainers-python facilitates the use of Docker containers for functional and integration testing.
For more information, see the docs.
Getting Started
>>> from testcontainers.postgres import PostgresContainer
>>> import sqlalchemy
>>> with PostgresContainer("postgres:16") as postgres:
... engine = sqlalchemy.create_engine(postgres.get_connection_url())
... with engine.begin() as connection:
... result = connection.execute(sqlalchemy.text("select version()"))
... version, = result.fetchone()
>>> version
'PostgreSQL 16...'
The snippet above will spin up a postgres database in a container. The get_connection_url() convenience method returns a sqlalchemy compatible url we use to connect to the database and retrieve the database version.
Contributing / Development / Release
See CONTRIBUTING.md for more details.
Configuration
| Env Variable | Example | Description |
|---|---|---|
TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE |
/var/run/docker.sock |
Path to Docker's socket used by ryuk |
TESTCONTAINERS_RYUK_PRIVILEGED |
false |
Run ryuk as a privileged container |
TESTCONTAINERS_RYUK_DISABLED |
false |
Disable ryuk |
RYUK_CONTAINER_IMAGE |
testcontainers/ryuk:0.7.0 |
Custom image for ryuk |
RYUK_RECONNECTION_TIMEOUT |
10s |
Reconnection timeout for Ryuk TCP socket before Ryuk reaps all dangling containers |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file testcontainers-4.7.2.tar.gz.
File metadata
- Download URL: testcontainers-4.7.2.tar.gz
- Upload date:
- Size: 60.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9976b1cdcdeb9feeae6a477073e7c8b02cd40ea44f1daa34b5da6d2c918dff0d
|
|
| MD5 |
90470d5269c223112b0d6137a39ddad4
|
|
| BLAKE2b-256 |
a9af6ca2ac43a6bd72b0f60d08307331aa91466d21ffd5c7935de0f828c63e84
|
File details
Details for the file testcontainers-4.7.2-py3-none-any.whl.
File metadata
- Download URL: testcontainers-4.7.2-py3-none-any.whl
- Upload date:
- Size: 99.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23b13cf8078f615a08c75197f227796d90c46df92d2b282ae7c39b1fc1a9c9ed
|
|
| MD5 |
6b4259fa8ab6206dc7873eeb5a8829e9
|
|
| BLAKE2b-256 |
7257907bdf32daaeaec6ed802a1f6724a40f2011b2c7eb8f5bde86876085808d
|