PyDocks¶
PyDocks is a pytest plugin that provides Docker container fixtures for integration tests. Each supported service exposes function- and session-scoped fixtures plus a cleanup helper, so tests can spin up real dependencies without managing Docker lifecycle by hand.
Quick start¶
pip install pydocks
import pytest
import asyncpg
@pytest.mark.asyncio
async def test_postgresql_execute_command(postgresql_container):
conn = await asyncpg.connect(
host="127.0.0.1",
port=postgresql_container.port,
user="postgres",
password="postgres",
database="postgres",
)
try:
assert await conn.fetchval("SELECT 1") == 1
finally:
await conn.close()
Available containers¶
| Feature | Fixtures |
|---|---|
| PostgreSQL | postgresql_container, postgresql_container_session, postgresql_clean_all_containers |
| Redis | redis_container, redis_container_session, redis_clean_all_containers |
| Valkey | valkey_container, valkey_container_session, valkey_clean_all_containers |
| Vault | vault_container, vault_container_session, vault_clean_all_containers |
| Ubuntu | ubuntu_container, ubuntu_container_session, ubuntu_clean_all_containers |
| Alpine | alpine_container, alpine_container_session, alpine_clean_all_containers |
| OpenTofu | opentofu_container, opentofu_container_session, opentofu_clean_all_containers |
Development¶
just install
just test-cov
just docs-serve # preview documentation locally
See the architecture guide for the feature-based layout and how to add a new container feature.