🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

pytest-databases

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pytest-databases

Reusable database fixtures for any and all databases.

0.13.0
Source
PyPI
Maintainers
1
ProjectStatus
CI/CDLatest Release ci Documentation Building
QualityCoverage Quality Gate Status Maintainability Rating Reliability Rating Security Rating
PackagePyPI - Version PyPI - Support Python Versions
CommunityDiscord Matrix Medium Twitter Blog
MetaLitestar 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 and 17 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://pytest-databases.readthedocs.io/

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

Keywords

alloydb

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts