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.18.0.tar.gz (324.9 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.18.0-py3-none-any.whl (40.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_databases-0.18.0.tar.gz
  • Upload date:
  • Size: 324.9 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.18.0.tar.gz
Algorithm Hash digest
SHA256 d49fa4e85494ec33dd6224affada1ddfdb83736b28f5ae40377220ad5dbbb658
MD5 e3dc89b827fc1f0d9f0cf9cc801f0c7a
BLAKE2b-256 f7cee0458cdb8d84b14156392b4bbc5575b6145b4ae6c3962a500e3d66002da3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytest_databases-0.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e2114c9e36ec7f4ff118453e9511e5cffb85294214838a70a8dee36c40340bd1
MD5 df24eb6cdf89ef1182949886e534a6e0
BLAKE2b-256 d2ae129e2529248eceb422e9051f408f752a78c80628700ffde94cc9edbf2d9d

See more details on using hashes here.

Provenance

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