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.17.0.tar.gz (330.3 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.17.0-py3-none-any.whl (33.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_databases-0.17.0.tar.gz
  • Upload date:
  • Size: 330.3 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.17.0.tar.gz
Algorithm Hash digest
SHA256 3918c932877d0b4e1252084fcae98fd4ee0315a6adc7409510e4fea8af5adf47
MD5 d84ca9f3806d350c42befc994954a353
BLAKE2b-256 167f58e6de47d1c4c59c1c31a8c8fb181a50bfe2737bcce5fe85a896cfb09b0b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytest_databases-0.17.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7831c0a5a4fd06b87902e95447b2e4b52ec8910d34ad94c6222e75db6950327
MD5 21f86344ffdea3ab816ba1756665dbb1
BLAKE2b-256 ec34acedc8d44ac86a62f1e3576c1adeba92479bf115962b0925c8d87e664bfb

See more details on using hashes here.

Provenance

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