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.16.0.tar.gz (315.2 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.16.0-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pytest_databases-0.16.0.tar.gz
Algorithm Hash digest
SHA256 5df82ac5650dc714d5341dad6cbe526dca183c430ef4a2e5de303267d420fbf0
MD5 6820c3e058ff68c814e5f496206da0d8
BLAKE2b-256 b46e49c740d77f80ff3c7c9bd8d791191555f987ed889a9cc243a1b7185e865c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_databases-0.16.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.16.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_databases-0.16.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c9d78dd89f67aee511b801533affb1af82ea77bafe23b08d7b762d8508a5cd2
MD5 ea225349438b5bb4caa33e8a4f67ed09
BLAKE2b-256 dea63665fc96d3b3e17a54bdd9488d870e923d34330e71be7e02989f8619d14f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_databases-0.16.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