Doltgres#

Integration with Doltgres using the dolthub/doltgresql Docker Image.

Doltgres is a PostgreSQL-compatible database with Git-like version control for tables and schemas.

Installation#

The fixture starts a running Doltgres service and validates readiness using the psql CLI bundled inside the container image, so no Python client driver is required to start the service:

pip install pytest-databases

Usage Example#

import psycopg
from pytest_databases.docker.doltgres import DoltgresService

pytest_plugins = ["pytest_databases.docker.doltgres"]


def test_doltgres(doltgres_service: DoltgresService) -> None:
    with psycopg.connect(
        host=doltgres_service.host,
        port=doltgres_service.port,
        user=doltgres_service.user,
        password=doltgres_service.password,
        dbname=doltgres_service.database,
    ) as conn:
        row = conn.execute("SELECT 1").fetchone()
        assert row is not None and row[0] == 1

Available Fixtures#

  • doltgres_service: Session-scoped fixture that provides a DoltgresService instance.

  • doltgres_image: The Docker image to use for Doltgres (defaults to "dolthub/doltgresql:latest", override with DOLTGRES_IMAGE).

  • doltgres_user: The application user configured in the container (defaults to "doltgres", override with DOLTGRES_USER).

  • doltgres_password: The application user password configured in the container (defaults to "super-secret", override with DOLTGRES_PASSWORD).

  • doltgres_root_password: The postgres superuser password configured in the container (defaults to "super-secret", override with DOLTGRES_ROOT_PASSWORD).

  • doltgres_database: The initial database configured in the container (defaults to "pytest_databases", override with DOLTGRES_DATABASE).

  • doltgres_port: Optional pinned host port for Doltgres (defaults to None, override with DOLTGRES_PORT).

Isolation Level#

By default, the doltgres_service fixture uses database isolation, where each worker gets its own database on a shared server. You can change this to server isolation by overriding the xdist_doltgres_isolation_level fixture:

import pytest


@pytest.fixture(scope="session")
def xdist_doltgres_isolation_level():
    return "server"

Service API#

Doltgres (PostgreSQL-compatible version-controlled database) container service fixtures.

class pytest_databases.docker.doltgres.DoltgresService(container: docker.models.containers.Container, host: str, port: int, database: str, user: str, password: str)[source]#

Bases: ServiceContainer

Service handle for a running Doltgres container.

database: str#
user: str#
password: str#
property db: str#

Alias for database matching DoltService.db.

__init__(container: docker.models.containers.Container, host: str, port: int, database: str, user: str, password: str) → None#
pytest_databases.docker.doltgres.doltgres_database() → str[source]#

Return the Doltgres database name.

pytest_databases.docker.doltgres.doltgres_image() → str[source]#

Return the Doltgres container image.

pytest_databases.docker.doltgres.doltgres_password() → str[source]#

Return the Doltgres application password.

pytest_databases.docker.doltgres.doltgres_port() → int | None[source]#

Return an optional pinned host port for Doltgres from DOLTGRES_PORT.

pytest_databases.docker.doltgres.doltgres_root_password() → str[source]#

Return the Doltgres superuser password.

pytest_databases.docker.doltgres.doltgres_service(docker_service: DockerService, xdist_doltgres_isolation_level: XdistIsolationLevel, doltgres_image: str, doltgres_user: str, doltgres_password: str, doltgres_root_password: str, doltgres_database: str, doltgres_port: int | None) → Generator[DoltgresService, None, None][source]#

Provide a running Doltgres container service.

Yields:

Active DoltgresService instance.

pytest_databases.docker.doltgres.doltgres_user() → str[source]#

Return the Doltgres application user.

pytest_databases.docker.doltgres.exec_doltgres_psql(container: docker.models.containers.Container, sql: str, *, user: str = 'postgres', password: str, database: str = 'postgres') → tuple[int, bytes][source]#

Execute a SQL statement inside a Doltgres container via bundled psql.

Parameters:
  • container – Running Doltgres container.

  • sql – SQL statement to execute.

  • user – Database user name.

  • password – Password for user.

  • database – Target database name.

Returns:

Tuple of (exit_code, raw_output_bytes).

pytest_databases.docker.doltgres.provide_doltgres_service(docker_service: DockerService, *, image: str, name: str, isolation_level: XdistIsolationLevel, user: str, password: str, root_password: str, database: str, port: int | None = None) → Generator[DoltgresService, None, None][source]#

Start and manage a Doltgres container service.

Yields:

Active DoltgresService instance.

Raises:

RuntimeError – If database or role initialization fails across retries.

pytest_databases.docker.doltgres.xdist_doltgres_isolation_level() → Literal['database', 'server'][source]#

Return the pytest-xdist isolation level for Doltgres.