Yugabyte#
Integration with Yugabyte DB
Installation#
pip install pytest-databases
The fixture provides a running Yugabyte service and validates availability with Yugabyte’s bundled tools. Use the service attributes with the PostgreSQL-compatible client, ORM, or application configuration you normally use.
Usage Example#
import pytest
import psycopg
from pytest_databases.docker.yugabyte import YugabyteService
pytest_plugins = ["pytest_databases.docker.yugabyte"]
@pytest.fixture(scope="session")
def yugabyte_uri(yugabyte_service: YugabyteService) -> str:
return (
f"postgresql://{yugabyte_service.user}:{yugabyte_service.password}"
f"@{yugabyte_service.host}:{yugabyte_service.port}/{yugabyte_service.database}?sslmode=disable"
)
def test_yugabyte_service(yugabyte_uri: str) -> None:
with psycopg.connect(yugabyte_uri) as conn:
db_open = conn.execute("SELECT 1").fetchone()
assert db_open is not None and db_open[0] == 1
Available Fixtures#
yugabyte_image: The Docker image to use for Yugabyte DB.yugabyte_user: The Yugabyte user exposed onyugabyte_service.yugabyte_password: The Yugabyte password exposed onyugabyte_service.yugabyte_database: The database created foryugabyte_service.yugabyte_service: A fixture that provides a Yugabyte DB service.
Service API#
YugabyteDB distributed SQL service fixtures.
- class pytest_databases.docker.yugabyte.YugabyteService(container: docker.models.containers.Container, host: str, port: int, database: str, user: str, password: str)[source]#
Bases:
ServiceContainerService container metadata for YugabyteDB.
- pytest_databases.docker.yugabyte.is_transient_yugabyte_error(output: str | bytes) bool[source]#
Return whether
outputcontains a transient YugabyteDB catalog or transaction conflict.
- pytest_databases.docker.yugabyte.provide_yugabyte_service(docker_service: DockerService, *, isolation_level: XdistIsolationLevel, image: str, user: str, password: str, database: str) Generator[YugabyteService, None, None][source]#
Start a YugabyteDB container, provision the test role and database, and verify readiness.
- Yields:
YugabyteService – Started YugabyteDB container service metadata.
- pytest_databases.docker.yugabyte.xdist_yugabyte_isolation_level() XdistIsolationLevel[source]#
Default
pytest-xdistisolation level for YugabyteDB.
- pytest_databases.docker.yugabyte.yugabyte_service(docker_service: DockerService, xdist_yugabyte_isolation_level: XdistIsolationLevel, yugabyte_image: str, yugabyte_user: str, yugabyte_password: str, yugabyte_database: str) Generator[YugabyteService, None, None][source]#
Provide a session-scoped YugabyteDB service container.
- Yields:
YugabyteService – Started YugabyteDB container service metadata.