GizmoSQL#

Integration with GizmoSQL, a high-performance SQL server built on Apache Arrow Flight SQL with DuckDB/SQLite backends.

Note

GizmoSQL always runs with TLS enabled using auto-generated self-signed certificates. When you connect from your own client code, configure TLS to skip certificate verification.

Installation#

pip install pytest-databases

Usage Example#

The plugin validates container readiness by running SELECT 4242 through gizmosql_client inside the container without requiring adbc-driver-flightsql at startup. Connect using the uri and connection_kwargs properties on GizmoSQLService. gizmosql_service uses DuckDB by default:

from adbc_driver_flightsql import dbapi as flightsql
from pytest_databases.docker.gizmosql import GizmoSQLService

pytest_plugins = ["pytest_databases.docker.gizmosql"]


def test(gizmosql_service: GizmoSQLService) -> None:
    with flightsql.connect(
        uri=gizmosql_service.uri,
        db_kwargs=gizmosql_service.connection_kwargs,
        autocommit=True,
    ) as conn:
        with conn.cursor() as cur:
            cur.execute("""
                CREATE TABLE test_table (id INTEGER, name VARCHAR);
                INSERT INTO test_table VALUES (1, 'test');
            """)

        with conn.cursor() as cur:
            cur.execute("SELECT * FROM test_table")
            result = cur.fetchone()
            assert result is not None
            assert result[0] == 1

Note

Due to Flight SQL semantics, DDL and DML statements should be combined in a single execute() call for immediate visibility across cursor operations.

Available Fixtures#

  • gizmosql_image: The Docker image to use for GizmoSQL (default: gizmodata/gizmosql:latest).

  • gizmosql_username: The username for authentication.

  • gizmosql_password: The password for authentication.

  • gizmosql_duckdb_service: A GizmoSQL service explicitly configured with the DuckDB backend.

  • gizmosql_sqlite_service: A GizmoSQL service explicitly configured with the SQLite backend.

  • gizmosql_service: The backward-compatible default, which returns gizmosql_duckdb_service.

  • xdist_gizmosql_isolation_level: database (default) keeps worker containers for reuse; server removes them at session end.

Both backend-specific fixtures can be requested in the same test session. They use distinct containers and share the image, username, password, TLS, readiness, and teardown configuration:

from pytest_databases.docker.gizmosql import GizmoSQLService


def test_backends(
    gizmosql_duckdb_service: GizmoSQLService,
    gizmosql_sqlite_service: GizmoSQLService,
) -> None:
    assert gizmosql_duckdb_service.uri != gizmosql_sqlite_service.uri

Parallel Testing (xdist)#

GizmoSQL assigns each pytest-xdist worker its own container per backend (gizmosql-<backend>_<worker>) because embedded DuckDB and SQLite instances do not provide independent server databases. This holds for both isolation levels; xdist_gizmosql_isolation_level only controls whether those containers are removed at session end (server) or kept for the next run (database).

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

Service API#

GizmoSQL (Apache Arrow Flight SQL with DuckDB/SQLite backends) container service fixtures.

class pytest_databases.docker.gizmosql.GizmoSQLService(container: docker.models.containers.Container, host: str, port: int, username: str, password: str, backend: Literal['duckdb', 'sqlite'] = 'duckdb')[source]#

Bases: ServiceContainer

Service container for GizmoSQL database.

GizmoSQL is a high-performance SQL server built on Apache Arrow Flight SQL with DuckDB/SQLite backends. The server always runs with TLS enabled using auto-generated self-signed certificates.

username: str#
password: str#
backend: GizmoSQLBackend = 'duckdb'#
property uri: str#

The gRPC+TLS URI for connecting to the service.

property connection_kwargs: dict[str, str]#

Standard ADBC Flight SQL db_kwargs for connecting to the service.

__init__(container: docker.models.containers.Container, host: str, port: int, username: str, password: str, backend: Literal['duckdb', 'sqlite'] = 'duckdb') → None#
pytest_databases.docker.gizmosql.exec_gizmosql(container: docker.models.containers.Container, sql: str, *, user: str, password: str) → tuple[int, bytes][source]#

Execute a SQL statement inside a GizmoSQL container using gizmosql_client.

Retries up to 3 times if gizmosql_client aborts with SIGABRT/SIGSEGV (exit codes 134 or 139 or double free or corruption) during C++ global destructor teardown after executing the Flight SQL command.

Parameters:
  • container – Running GizmoSQL container.

  • sql – SQL statement to execute.

  • user – Username for Flight SQL authentication.

  • password – Password for Flight SQL authentication.

Returns:

Tuple of (exit_code, raw_output_bytes).

pytest_databases.docker.gizmosql.gizmosql_connection(gizmosql_service: GizmoSQLService) → Generator[Any, None, None][source]#

Yield a deprecated ADBC Flight SQL connection connected to gizmosql_service.

pytest_databases.docker.gizmosql.gizmosql_duckdb_service(docker_service: DockerService, xdist_gizmosql_isolation_level: XdistIsolationLevel, gizmosql_image: str, gizmosql_username: str, gizmosql_password: str) → Generator[GizmoSQLService, None, None][source]#

Provide a GizmoSQL service configured with the DuckDB backend.

Yields:

A DuckDB-backed GizmoSQLService.

pytest_databases.docker.gizmosql.gizmosql_image() → str[source]#

Return the container image tag for GizmoSQL.

pytest_databases.docker.gizmosql.gizmosql_password() → str[source]#

Return the default password for GizmoSQL.

pytest_databases.docker.gizmosql.gizmosql_service(gizmosql_duckdb_service: GizmoSQLService) → GizmoSQLService[source]#

Provide the default DuckDB-backed GizmoSQL service.

pytest_databases.docker.gizmosql.gizmosql_sqlite_service(docker_service: DockerService, xdist_gizmosql_isolation_level: XdistIsolationLevel, gizmosql_image: str, gizmosql_username: str, gizmosql_password: str) → Generator[GizmoSQLService, None, None][source]#

Provide a GizmoSQL service configured with the SQLite backend.

Yields:

A SQLite-backed GizmoSQLService.

pytest_databases.docker.gizmosql.gizmosql_username() → str[source]#

Return the default username for GizmoSQL.

pytest_databases.docker.gizmosql.provide_deprecated_gizmosql_connection(service: GizmoSQLService) → Generator[Any, None, None][source]#

Yield a deprecated ADBC Flight SQL connection while emitting a DeprecationWarning.

Parameters:

service – Running GizmoSQLService instance.

Yields:

An active ADBC Flight SQL DBAPI connection.

pytest_databases.docker.gizmosql.provide_gizmosql_service(docker_service: DockerService, isolation_level: XdistIsolationLevel, image: str, username: str, password: str, backend: GizmoSQLBackend) → Generator[GizmoSQLService, None, None][source]#

Start and yield a GizmoSQL container configured for a specific backend.

The embedded DuckDB and SQLite backends cannot host independent databases, so under pytest-xdist every worker gets its own container per backend regardless of isolation_level. isolation_level only decides whether the container is removed at session end (server) or kept for reuse.

Parameters:
  • docker_service – Container lifecycle manager.

  • isolation_level – pytest-xdist isolation level.

  • image – Container image tag.

  • username – Flight SQL username.

  • password – Flight SQL password.

  • backend – Embedded storage backend ("duckdb" or "sqlite").

Yields:

A running GizmoSQLService instance.

pytest_databases.docker.gizmosql.xdist_gizmosql_isolation_level() → Literal['database', 'server'][source]#

Return the default pytest-xdist isolation level for GizmoSQL.