pytest-databases

Configures Docker-backed database fixtures for pytest integration tests.

Updated Aug 17, 2026
One-click install
npx skills add https://github.com/renjianguo666/litecms --skill pytest-databases-renjianguo666
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytest-databases
Source: https://github.com/renjianguo666/litecms/tree/main/.agents/skills/pytest-databases
Command: npx skills add https://github.com/renjianguo666/litecms --skill pytest-databases-renjianguo666

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Setting up real databases for integration tests requires manual container management, port handling, and cleanup. This Skill guides the use of pytest-databases fixtures so tests run against actual PostgreSQL, MySQL, Oracle, and other services without hand-rolled lifecycle code. ## Core Features & Use Cases - Ready-made service fixtures: Enable plugins like pytest_databases.docker.postgres in conftest.py and consume fixtures such as postgres_service and postgres_connection. - Parallel test isolation: Configure database-level or server-level isolation for pytest-xdist workers so parallel runs do not share schemas. - Configuration overrides: Customize images, passwords, and platforms (including ARM/Apple Silicon) via session-scoped fixtures or environment variables. - Use Case: Add pytest_plugins = ["pytest_databases.docker.postgres"] to conftest.py, then write an async test that inserts and queries rows through postgres_connection against a real containerized PostgreSQL instance. ## Quick Start Ask the AI to set up a PostgreSQL integration test using pytest-databases fixtures in your conftest.py and test files.

Frequently Asked Questions about pytest-databases

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up PostgreSQL fixtures in pytest with Docker?

Add `pytest_plugins = ["pytest_databases.docker.postgres"]` to your conftest.py, then request the `postgres_service` or `postgres_connection` fixtures in your tests. The plugin starts the container, waits for readiness, and tears it down automatically.

How do I run pytest database tests in parallel with pytest-xdist?

pytest-databases supports two isolation levels for xdist: database isolation (default) gives each worker a separate database in one shared container, while server isolation gives each worker its own container. Set the `xdist_postgres_isolation_level` fixture to "database" or "server".

Which databases does pytest-databases support?

It supports PostgreSQL, MySQL, MariaDB, Oracle, SQL Server, Redis, Valkey, Elasticsearch, Spanner, BigQuery, and MinIO. Each database has its own plugin module, service class, and versioned fixtures such as `postgres_18_service` or `mysql_8_service`.

Does pytest-databases work on Apple Silicon (ARM)?

Yes, but some database images need an explicit platform. Define a session-scoped `platform` fixture returning "linux/arm64" in conftest.py so Docker pulls and runs the correct image architecture.

When should I not use pytest-databases fixtures?

Avoid it for unit tests that should use mocked database clients, and for projects not using pytest. The fixtures are designed for integration tests that need real containerized services, not for mocking driver behavior.