Skip to main content

Reusable database fixtures for any and all databases.

Project description

Project Status
CI/CD Latest Release ci Documentation Building
Quality Coverage Quality Gate Status Maintainability Rating Reliability Rating Security Rating
Package PyPI - Version PyPI - Support Python Versions
Community Discord Matrix Medium Twitter Blog
Meta Litestar Project types - Mypy License - MIT Litestar Sponsors linting - Ruff code style - Ruff

Pytest Databases

Ready-made database fixtures for your pytest tests.

Features

  • 🚀 Easy-to-use database fixtures
  • 🔄 Support for multiple database types
  • 🐳 Docker integration for isolated testing environments
  • ⚡ Fast and efficient test execution
  • 🔧 Highly configurable

pytest-databases uses the Docker Python SDK to manage the startup and shutdown of database services in containers. The following databases are currently available:

  • Postgres: Version 12, 13, 14, 15, 16, 17 and 18 are available
  • MySQL: Version 5.6, 5.7 and 8 are available
  • Oracle: Version 18c XE and 23C Free are available
  • SQL Server: Version 2022 is available
  • Google AlloyDB Omni: Simplified Omni installation for easy testing.
  • Google Spanner: The latest cloud-emulator from Google is available
  • Google BigQuery: Unofficial BigQuery emulator
  • CockroachDB: Version latest is available
  • Redis: Latest version
  • Valkey: Latest version
  • Dragonfly: Latest version
  • KeyDB: Latest version
  • Elasticsearch: Version 7 and 8 are available
  • Azure blob storage: Via azurite
  • Minio: Latest version

Installation

Quick install for postgres:

pip install pytest-databases[postgres]

Quick Start

  • Add to your pytest conftest.py:
pytest_plugins = ["pytest_databases.docker.postgres"]
  • Use in your tests:
from pytest_databases.docker.postgres import PostgresService
import psycopg

def test_one(postgres_service: PostgresService) -> None:
    with psycopg.connect(
        f"postgresql://{postgres_service.user}:{postgres_service.password}@{postgres_service.host}:{postgres_service.port}/{postgres_service.database}",
        autocommit=True,
    ) as conn:
        result = conn.execute("SELECT 1")
        assert result

Documentation

Full documentation is available at https://litestar-org.github.io/pytest-databases/latest/

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • The Litestar Framework team
  • The pytest community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_databases-0.19.0.tar.gz (350.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_databases-0.19.0-py3-none-any.whl (41.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest_databases-0.19.0.tar.gz.

File metadata

  • Download URL: pytest_databases-0.19.0.tar.gz
  • Upload date:
  • Size: 350.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pytest_databases-0.19.0.tar.gz
Algorithm Hash digest
SHA256 ba7b8e51b551455daf3bd144384f6d4fba23d747b001f071795b02e6be2a3cbf
MD5 e4135e8e7cc80a518365ab4f5ed5eabe
BLAKE2b-256 ab4ee899556b3876eec2db9bd630ad3054ced94a9541c26319bec5c4cd00579d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_databases-0.19.0.tar.gz:

Publisher: release.yaml on litestar-org/pytest-databases

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_databases-0.19.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_databases-0.19.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d14651e23a716ed6f2317bf9ac317c9e7891db701253abf78e9cef1049e8f26b
MD5 5c85e00fc3b91b03f4ff577c3354ad63
BLAKE2b-256 def4d6e2edae47a0421a8531a9805fb787b993380222f00dc25cee1634f55f3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_databases-0.19.0-py3-none-any.whl:

Publisher: release.yaml on litestar-org/pytest-databases

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page