### Install Postgres Fixture Source: https://github.com/litestar-org/pytest-databases/blob/main/README.md Install the pytest-databases package with the postgres extra for quick setup. ```bash pip install pytest-databases[postgres] ``` -------------------------------- ### Test Valkey service with ValkeyService fixture Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/valkey.md Use the ValkeyService fixture to obtain connection details and interact with a Valkey instance. This example demonstrates setting and getting a key using the Valkey client. ```python from valkey import Valkey from pytest_databases.docker.valkey import ValkeyService pytest_plugins = ["pytest_databases.docker.valkey"] def test(valkey_service: ValkeyService) -> None: client = Valkey( host=valkey_service.host, port=valkey_service.port, db=valkey_service.db ) client.set("test_key", "test_value") assert client.get("test_key") == b"test_value" ``` -------------------------------- ### MinIO Usage Example with MinioService Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/minio.md Demonstrates how to use the MinioService fixture to create a MinIO client and interact with it. This example creates a bucket and checks its existence. ```python from minio import Minio from pytest_databases.docker.minio import MinioService pytest_plugins = ["pytest_databases.docker.minio"] def test(minio_service: MinioService) -> None: client = Minio( endpoint=minio_service.endpoint, access_key=minio_service.access_key, secret_key=minio_service.secret_key, secure=minio_service.secure, ) client.make_bucket("test-bucket") assert client.bucket_exists("test-bucket") ``` -------------------------------- ### MinIO Usage Example with Minio Client Fixture Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/minio.md Demonstrates how to use the pre-configured MinIO client fixture directly. This example creates a bucket and checks its existence using the injected client. ```python def test(minio_client: Minio) -> None: minio_client.make_bucket("test-bucket") assert client.bucket_exists("test-bucket") ``` -------------------------------- ### Oracle Database Usage Example Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/oracle.md Demonstrates how to connect to an Oracle database service managed by pytest-databases and execute a simple query. Ensure the 'oracledb' library is installed. ```python import oracledb from pytest_databases.docker.oracle import OracleService pytest_plugins = ["pytest_databases.docker.oracle"] def test(oracle_service: OracleService) -> None: # ``oracledb`` is user-owned application code; pytest-databases only # starts the service and provides connection metadata. conn = oracledb.connect( user=oracle_service.user, password=oracle_service.password, service_name=oracle_service.service_name, host=oracle_service.host, port=oracle_service.port, ) with conn.cursor() as cur: cur.execute("SELECT 1 FROM dual") res = cur.fetchone()[0] assert res == 1 ``` -------------------------------- ### Install pytest-databases with Valkey support Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/valkey.md Install the necessary package to enable Valkey integration. ```bash pip install pytest-databases[valkey] ``` -------------------------------- ### Test RustFS with boto3 Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/rustfs.md Example of using the RustFS fixture with the boto3 S3 client to interact with the service. Ensure you have boto3 installed separately. ```python import boto3 from botocore.client import Config from pytest_databases.docker.rustfs import RustfsService pytest_plugins = ["pytest_databases.docker.rustfs"] def test_with_boto3(rustfs_service: RustfsService, rustfs_default_bucket_name: str) -> None: scheme = "https" if rustfs_service.secure else "http" endpoint_url = f"{scheme}://{rustfs_service.endpoint}" s3 = boto3.client( "s3", endpoint_url=endpoint_url, aws_access_key_id=rustfs_service.access_key, aws_secret_access_key=rustfs_service.secret_key, config=Config(signature_version="s3v4"), region_name="us-east-1", ) # The default bucket is automatically created by the fixture response = s3.list_buckets() bucket_names = [b["Name"] for b in response["Buckets"]] assert rustfs_default_bucket_name in bucket_names ``` -------------------------------- ### Install pytest-databases with MinIO support Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/minio.md Install the necessary package for MinIO integration. This command installs pytest-databases and its MinIO extra dependencies. ```bash pip install pytest-databases[minio] ``` -------------------------------- ### Usage Example Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/mariadb.md Demonstrates how to use the mariadb_service fixture to connect to a running MariaDB instance and execute a simple query. ```APIDOC ## Usage Example ```python import mariadb from pytest_databases.docker.mariadb import MariaDBService pytest_plugins = ["pytest_databases.docker.mariadb"] def test(mariadb_service: MariaDBService) -> None: with mariadb.connect( host=mariadb_service.host, port=mariadb_service.port, user=mariadb_service.user, database=mariadb_service.db, password=mariadb_service.password, ) as conn, conn.cursor() as cursor: cursor.execute("select 1 as is_available") resp = cursor.fetchone() assert resp is not None and resp[0] == 1 ``` ``` -------------------------------- ### Usage Example for Elasticsearch 7.x Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/elasticsearch.md Demonstrates how to use the Elasticsearch 7.x service fixture to create an Elasticsearch client and verify its version. ```python from elasticsearch7 import Elasticsearch from pytest_databases.docker.elastic_search import ElasticsearchService pytest_plugins = ["pytest_databases.docker.elastic_search"] def test(elasticsearch_7_service: ElasticsearchService) -> None: with Elasticsearch( hosts=[ { "host": elasticsearch_7_service.host, "port": elasticsearch_7_service.port, "scheme": elasticsearch_7_service.scheme, } ], verify_certs=False, http_auth=(elasticsearch_7_service.user, elasticsearch_7_service.password), ) as client: info = client.info() assert info["version"]["number"] == "7.17.19" ``` -------------------------------- ### Spanner Service and Database Connection Example Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/spanner.md Example demonstrating how to use the spanner_service fixture to establish a connection to the Spanner Emulator and perform a basic SQL query. Ensure the Spanner Emulator is running and accessible. ```python from google.cloud import spanner import contextlib from pytest_databases.docker.spanner import SpannerService pytest_plugins = ["pytest_databases.docker.spanner"] def test(spanner_service: SpannerService) -> None: spanner_client = spanner.Client( project=spanner_service.project, credentials=spanner_service.credentials, client_options=spanner_service.client_options, ) instance = spanner_client.instance(spanner_service.instance_name) with contextlib.suppress(Exception): instance.create() database = instance.database(spanner_service.database_name) with contextlib.suppress(Exception): database.create() with database.snapshot() as snapshot: resp = next(iter(snapshot.execute_sql("SELECT 1"))) assert resp[0] == 1 ``` -------------------------------- ### Install Elasticsearch 7.x Support Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/elasticsearch.md Install the necessary package for Elasticsearch 7.x integration. ```bash pip install pytest-databases[elasticsearch7] ``` -------------------------------- ### Usage Example for Elasticsearch 8.x Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/elasticsearch.md Demonstrates how to use the Elasticsearch 8.x service fixture to create an Elasticsearch client and verify its version. ```python from elasticsearch8 import Elasticsearch from pytest_databases.docker.elastic_search import ElasticsearchService pytest_plugins = ["pytest_databases.docker.elastic_search"] def test(elasticsearch_8_service: ElasticsearchService) -> None: with Elasticsearch( hosts=[ { "host": elasticsearch_8_service.host, "port": elasticsearch_8_service.port, "scheme": elasticsearch_8_service.scheme, } ], verify_certs=False, basic_auth=(elasticsearch_8_service.user, elasticsearch_8_service.password), ) as client: info = client.info() assert info["version"]["number"] == "8.13.0" ``` -------------------------------- ### Install pytest-databases with GizmoSQL support Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/gizmosql.md Install the necessary package to enable GizmoSQL integration. This command installs pytest-databases along with the GizmoSQL extra dependencies. ```bash pip install pytest-databases[gizmosql] ``` -------------------------------- ### Dolt Usage Example with mysql.connector Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/dolt.md Demonstrates how to connect to a Dolt service provided by the dolt_service fixture and execute a simple query. ```python import mysql.connector from pytest_databases.docker.dolt import DoltService pytest_plugins = ["pytest_databases.docker.dolt"] def test(dolt_service: DoltService) -> None: with mysql.connector.connect( host=dolt_service.host, port=dolt_service.port, user=dolt_service.user, database=dolt_service.db, password=dolt_service.password, ) as conn, conn.cursor() as cursor: cursor.execute("select 1 as is_available") resp = cursor.fetchone() assert resp is not None and resp[0] == 1 ``` -------------------------------- ### Spanner Connection Fixture Example Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/spanner.md Example showing how to use the spanner_connection fixture to obtain a Spanner client instance. This fixture provides a pre-configured spanner.Client object. ```python from google.cloud import spanner def test(spanner_connection: spanner.Client) -> None: assert isinstance(spanner_connection, spanner.Client) ``` -------------------------------- ### Install pytest-databases with Redis support Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/redis.md Install the necessary package to enable Redis integration. ```bash pip install pytest-databases[redis] ``` -------------------------------- ### Install Elasticsearch 8.x Support Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/elasticsearch.md Install the necessary package for Elasticsearch 8.x integration. ```bash pip install pytest-databases[elasticsearch8] ``` -------------------------------- ### Install pytest-databases with BigQuery support Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/bigquery.md Install the necessary package to enable BigQuery integration. This command installs pytest-databases along with the BigQuery extra dependencies. ```bash pip install pytest-databases[bigquery] ``` -------------------------------- ### Install pytest-databases with Spanner Support Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/spanner.md Install the necessary package for Spanner integration. This command installs pytest-databases along with the Spanner extra dependencies. ```bash pip install pytest-databases[spanner] ``` -------------------------------- ### Install pytest-databases with Oracle support Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/oracle.md Install the necessary package to enable Oracle database integration. This command installs pytest-databases with the Oracle extra. ```bash pip install pytest-databases[oracle] ``` -------------------------------- ### Install pytest-databases with Azure support Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/azure_blob_storage.md Install the necessary package to enable Azure Blob Storage integration. ```bash pip install pytest-databases[azure] ``` -------------------------------- ### Install pytest-databases Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/getting-started/installation.md Install the base pytest-databases package using pip. ```bash pip install pytest-databases ``` -------------------------------- ### MongoDB Service Usage Example Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/mongodb.md Demonstrates how to use the `mongodb_service` fixture to connect to a running MongoDB instance and perform basic database operations like insertion and retrieval. ```python import pymongo from pytest_databases.docker.mongodb import MongoDBService pytest_plugins = ["pytest_databases.docker.mongodb"] def test_mongodb_service(mongodb_service: MongoDBService) -> None: client = pymongo.MongoClient( host=mongodb_service.host, port=mongodb_service.port, username=mongodb_service.username, password=mongodb_service.password, ) try: client.admin.command("ping") db = client[mongodb_service.database] collection = db["mycollection"] collection.insert_one({"name": "test_document", "value": 1}) result = collection.find_one({"name": "test_document"}) assert result is not None assert result["value"] == 1 finally: client.close() ``` -------------------------------- ### Test PostgreSQL service connection and query Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/postgres.md Demonstrates how to use the `PostgresService` fixture to obtain connection details and execute a simple query. Ensure the `psycopg` library is installed. ```python import psycopg from pytest_databases.docker.postgres import PostgresService pytest_plugins = ["pytest_databases.docker.postgres"] def test(postgres_service: PostgresService) -> None: with psycopg.connect( f"postgresql://{postgres_service.user}:{postgres_service.password}@{postgres_service.host}:{postgres_service.port}/{postgres_service.database}" ) as conn: db_open = conn.execute("SELECT 1").fetchone() assert db_open is not None and db_open[0] == 1 ``` -------------------------------- ### Install pytest-databases with Yugabyte support Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/yugabyte.md Install the necessary package to enable Yugabyte DB integration. This command installs pytest-databases along with the Yugabyte extra dependencies. ```bash pip install pytest-databases[yugabyte] ``` -------------------------------- ### Test Azure Blob Storage Container Creation Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/azure_blob_storage.md Example demonstrating how to create and verify an Azure Blob Storage container using the AzureBlobStorageService fixture. ```python from azure.storage.blob import BlobServiceClient from pytest_databases.docker.azure_blob import AzureBlobStorageService pytest_plugins = ["pytest_databases.docker.azure_blob"] def test(azure_blob_storage_service: AzureBlobStorageService) -> None: client = BlobServiceClient.from_connection_string( azure_blob_storage_service.connection_string ) container = client.get_container_client(azure_blob_storage_service.container_name) container.create_container() assert container.exists() ``` -------------------------------- ### Yugabyte DB Usage Example with psycopg Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/yugabyte.md This example demonstrates how to use the YugabyteService fixture to obtain a connection URI and then connect to the Yugabyte database using psycopg to execute a simple query. ```python 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 ``` -------------------------------- ### Install Multiple Database Extras Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/getting-started/installation.md Install pytest-databases with support for multiple databases simultaneously using pip extras. ```bash pip install pytest-databases[postgres,mysql,redis] ``` -------------------------------- ### Install pytest-databases with MSSQL support Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/sqlserver.md Install the necessary package to enable SQL Server integration. This includes the 'mssql' extra for compatibility. ```bash pip install pytest-databases[mssql] ``` -------------------------------- ### Install pytest-databases with CockroachDB support Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/cockroachdb.md Install the necessary package to enable CockroachDB integration. The 'cockroachdb' extra is a compatibility group and does not bundle a client. ```bash pip install pytest-databases[cockroachdb] ``` -------------------------------- ### Test GizmoSQL Connection Fixture Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/gizmosql.md Example demonstrating the use of the `gizmosql_connection` fixture for direct database operations. DDL and DML statements should be combined in a single execute call. ```python pytest_plugins = ["pytest_databases.docker.gizmosql"] def test(gizmosql_connection) -> None: with gizmosql_connection.cursor() as cur: cur.execute(""" CREATE TABLE test_table (id INTEGER, name VARCHAR); INSERT INTO test_table VALUES (1, 'test'); """) with gizmosql_connection.cursor() as cur: cur.execute("SELECT * FROM test_table") result = cur.fetchone() assert result is not None assert result[0] == 1 ``` -------------------------------- ### Test Azure Blob Storage Container Creation with BlobServiceClient Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/azure_blob_storage.md Example demonstrating how to create and verify an Azure Blob Storage container directly using a BlobServiceClient. ```python def test(azure_blob_storage_client: BlobServiceClient) -> None: container = azure_blob_storage_client.get_container_client("test-container") container.create_container() assert container.exists() ``` -------------------------------- ### Install Pytest-Databases with MongoDB Support Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/mongodb.md Install the necessary package to enable MongoDB integration. This includes the core pytest-databases library and the MongoDB extra. ```bash pip install pytest-databases[mongodb] ``` -------------------------------- ### Test Valkey connection with Valkey connection fixture Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/valkey.md Utilize the valkey_connection fixture for direct interaction with a Valkey instance. This example shows setting and retrieving a key using the provided connection. ```python from valkey import Valkey def test(valkey_connection: Valkey) -> None: valkey_connection.set("test_key", "test_value") assert valkey_connection.get("test_key") == b"test_value" ``` -------------------------------- ### Test GizmoSQL Service with ADBC Flight SQL Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/gizmosql.md Example of using the `gizmosql_service` fixture to obtain connection details and interact with GizmoSQL using ADBC Flight SQL. Ensure certificate verification is skipped for testing. ```python from adbc_driver_flightsql import dbapi as flightsql from pytest_databases.docker.gizmosql import GizmoSQLService, _make_connection_kwargs pytest_plugins = ["pytest_databases.docker.gizmosql"] def test(gizmosql_service: GizmoSQLService) -> None: db_kwargs = _make_connection_kwargs( gizmosql_service.username, gizmosql_service.password, ) with flightsql.connect( uri=gizmosql_service.uri, db_kwargs=db_kwargs, autocommit=True, ) as conn: with conn.cursor() as cur: cur.execute("SELECT 1") result = cur.fetchone() assert result is not None and result[0] == 1 ``` -------------------------------- ### Test MariaDB Connection Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/mariadb.md Example of connecting to a MariaDB service provided by pytest-databases and executing a simple query to verify availability. ```python import mariadb from pytest_databases.docker.mariadb import MariaDBService pytest_plugins = ["pytest_databases.docker.mariadb"] def test(mariadb_service: MariaDBService) -> None: with mariadb.connect( host=mariadb_service.host, port=mariadb_service.port, user=mariadb_service.user, database=mariadb_service.db, password=mariadb_service.password, ) as conn, conn.cursor() as cursor: cursor.execute("select 1 as is_available") resp = cursor.fetchone() assert resp is not None and resp[0] == 1 ``` -------------------------------- ### Test Redis connection using RedisService fixture Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/redis.md Demonstrates how to use the RedisService fixture to get connection details and interact with a Redis instance. ```python import redis from pytest_databases.docker.redis import RedisService pytest_plugins = ["pytest_databases.docker.redis"] def test(redis_service: RedisService) -> None: client = redis.Redis( host=redis_service.host, port=redis_service.port, db=redis_service.db ) client.set("test_key", "test_value") assert client.get("test_key") == b"test_value" ``` -------------------------------- ### Test BigQuery queries using BigQueryService fixture Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/bigquery.md Example of how to use the BigQueryService fixture to obtain a BigQuery client and execute a test query. Ensure the pytest_plugins are correctly set. ```python from google.cloud import bigquery from pytest_databases.docker.bigquery import BigQueryService pytest_plugins = ["pytest_databases.docker.bigquery"] def test(bigquery_service: BigQueryService) -> None: client = bigquery.Client( project=bigquery_service.project, client_options=bigquery_service.client_options, credentials=bigquery_service.credentials, ) job = client.query(query="SELECT 1 as one") resp = list(job.result()) assert resp[0].one == 1 ``` -------------------------------- ### Configure Dolt Isolation Level to Server Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/dolt.md Example of overriding the default database isolation level to server isolation for Dolt fixtures. ```python @pytest.fixture(scope="session") def xdist_dolt_isolation_level(): return "server" ``` -------------------------------- ### CockroachDB Usage Example with psycopg Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/cockroachdb.md A pytest fixture demonstrating how to obtain a CockroachDB connection URI and use it with psycopg to test database connectivity. ```python import pytest import psycopg from pytest_databases.docker.cockroachdb import CockroachDBService pytest_plugins = ["pytest_databases.docker.cockroachdb"] @pytest.fixture(scope="session") def cockroach_uri(cockroachdb_service: CockroachDBService) -> str: return ( f"postgresql://root@{cockroachdb_service.host}:{cockroachdb_service.port}" f"/{cockroachdb_service.database}?sslmode=disable" ) def test(cockroach_uri: str) -> None: with psycopg.connect(cockroach_uri) as conn: db_open = conn.execute("SELECT 1").fetchone() assert db_open is not None and db_open[0] == 1 ``` -------------------------------- ### Test SQL Server Service Availability Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/sqlserver.md A basic pytest fixture example demonstrating how to connect to a running SQL Server service and verify its availability by executing a simple query. ```python import pyodbc from pytest_databases.docker.mssql import MSSQLService pytest_plugins = ["pytest_databases.docker.mssql"] def test_sql_server_service(mssql_service: MSSQLService) -> None: with pyodbc.connect(mssql_service.connection_string) as conn: cursor = conn.cursor() cursor.execute("SELECT 1 AS is_available") row = cursor.fetchone() assert row is not None and row[0] == 1 ``` -------------------------------- ### Connect using PostgreSQL Service Fixture Details Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/getting-started/basic-usage.md Use the `postgres_service` fixture to retrieve connection parameters and establish a connection using a client like psycopg. ```python import psycopg from pytest_databases.docker.postgres import PostgresService # Example using the Service Fixture def test_connection_with_service_details(postgres_service: PostgresService) -> None: conn_str = ( f"postgresql://{postgres_service.user}:{postgres_service.password}@" f"{postgres_service.host}:{postgres_service.port}/{postgres_service.database}" ) with psycopg.connect(conn_str, autocommit=True) as conn: with conn.cursor() as cursor: cursor.execute("SELECT 1") assert cursor.fetchone() == (1,) ``` -------------------------------- ### Connect to MySQL Service and Execute Query Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/mysql.md This snippet shows how to establish a connection to a MySQL service provided by pytest-databases and execute a simple query to verify availability. It uses the mysql.connector library. ```python import mysql.connector from pytest_databases.docker.mysql import MySQLService pytest_plugins = ["pytest_databases.docker.mysql"] def test(mysql_service: MySQLService) -> None: with mysql.connector.connect( host=mysql_service.host, port=mysql_service.port, user=mysql_service.user, database=mysql_service.db, password=mysql_service.password, ) as conn, conn.cursor() as cursor: cursor.execute("select 1 as is_available") resp = cursor.fetchone() assert resp is not None and resp[0] == 1 ``` -------------------------------- ### Test PostgreSQL connection and table operations Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/postgres.md Shows how to use the `postgres_connection` fixture for direct database operations like creating a table and querying it. This fixture provides an active connection object. ```python def test(postgres_connection: psycopg.Connection) -> None: postgres_connection.execute("CREATE TABLE if not exists simple_table as SELECT 1") result = postgres_connection.execute("select * from simple_table").fetchone() assert result is not None and result[0] == 1 ``` -------------------------------- ### Service API: pytest_databases.docker.mssql.mssql_service() Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/sqlserver.md Provides a SQL Server service fixture. ```APIDOC ### pytest_databases.docker.mssql.mssql_service(docker_service: DockerService, xdist_mssql_isolation_level: XdistIsolationLevel, mssql_image: str, mssql_user: str, mssql_password: str, mssql_database: str) → Generator[[MSSQLService](#pytest_databases.docker.mssql.MSSQLService), None, None] Provides a SQL Server service fixture. ``` -------------------------------- ### Test BigQuery client instance using bigquery_client fixture Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/bigquery.md Verify that the bigquery_client fixture correctly provides an instance of google.cloud.bigquery.Client. ```python def test(bigquery_client: bigquery.Client) -> None: assert isinstance(bigquery_client, bigquery.Client) ``` -------------------------------- ### Test Redis connection using redis_connection fixture Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/redis.md Demonstrates how to use the redis_connection fixture to directly obtain a Redis connection object for testing. ```python def test(redis_connection: redis.Redis) -> None: redis_connection.set("test_key", "test_value") assert redis_connection.get("test_key") == b"test_value" ``` -------------------------------- ### Available Fixtures Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/sqlserver.md List of fixtures available for SQL Server integration. ```APIDOC * `mssql_image`: The Docker image to use for SQL Server. * `mssql_user`: The SQL Server user exposed on `mssql_service`. * `mssql_password`: The SQL Server password exposed on `mssql_service`. * `mssql_database`: The database created for `mssql_service`. * `mssql_service`: A fixture that provides a SQL Server service. ``` -------------------------------- ### RustFS Fixtures Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/rustfs.md Provides various fixtures for configuring and accessing the RustFS service and its default bucket. ```APIDOC ### pytest_databases.docker.rustfs.rustfs_access_key() -> str Provides the access key for RustFS. ### pytest_databases.docker.rustfs.rustfs_secret_key() -> str Provides the secret key for RustFS. ### pytest_databases.docker.rustfs.rustfs_secure() -> bool Indicates whether to use HTTPS for RustFS. ### pytest_databases.docker.rustfs.xdist_rustfs_isolation_level() -> Literal['database', 'server'] Determines the isolation level for RustFS when using pytest-xdist. ### pytest_databases.docker.rustfs.rustfs_default_bucket_name(xdist_rustfs_isolation_level: Literal['database', 'server']) -> str Provides the name of the default RustFS bucket, considering the isolation level. ### pytest_databases.docker.rustfs.rustfs_service(docker_service: DockerService, rustfs_access_key: str, rustfs_secret_key: str, rustfs_secure: bool, rustfs_default_bucket_name: str, xdist_rustfs_isolation_level: XdistIsolationLevel) -> Generator[[RustfsService], None, None] A fixture that provides a configured RustFS service instance. ``` -------------------------------- ### MinIO Fixtures Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/minio.md Provides various fixtures for interacting with MinIO, including access keys, security settings, the service itself, and a pre-configured client. ```APIDOC ### Fixture: minio_access_key #### Description Provides the access key for MinIO. Defaults to `os.getenv('MINIO_ACCESS_KEY', 'minio')`. ### Fixture: minio_secret_key #### Description Provides the secret key for MinIO. Defaults to `os.getenv('MINIO_SECRET_KEY', 'minio123')`. ### Fixture: minio_secure #### Description Provides a boolean indicating whether to use HTTPS for MinIO. Defaults to `os.getenv('MINIO_SECURE', 'false')`. ### Fixture: minio_service #### Description Provides a MinIO service instance, configured with the necessary credentials and settings. ### Fixture: minio_client #### Description Provides a pre-configured MinIO client instance ready for use in tests. ``` -------------------------------- ### MariaDBService Class Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/mariadb.md Provides attributes for connecting to a MariaDB service, including host, port, database name, user, and password. ```APIDOC ### *class* pytest_databases.docker.mariadb.MariaDBService(container: 'Container', host: 'str', port: 'int', db: 'str', user: 'str', password: 'str') Bases: `ServiceContainer` #### db *: str* #### user *: str* #### password *: str* ``` -------------------------------- ### Service API: pytest_databases.docker.mssql.mssql_image() Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/sqlserver.md Returns the Docker image name for SQL Server. ```APIDOC ### pytest_databases.docker.mssql.mssql_image() → str Returns the Docker image name for SQL Server. ``` -------------------------------- ### Service API: pytest_databases.docker.mssql.mssql_password() Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/sqlserver.md Returns the password for SQL Server authentication. ```APIDOC ### pytest_databases.docker.mssql.mssql_password() → str Returns the password for SQL Server authentication. ``` -------------------------------- ### Service API: pytest_databases.docker.mssql.mssql_database() Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/sqlserver.md Returns the database name created for the SQL Server service. ```APIDOC ### pytest_databases.docker.mssql.mssql_database() → str Returns the database name created for the SQL Server service. ``` -------------------------------- ### Available Fixtures Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/mariadb.md Lists the available fixtures for managing MariaDB services, including general and version-specific options. ```APIDOC ## Available Fixtures * `mariadb_service`: A fixture that provides a MariaDB service (11.4 LTS). * `mariadb_user`: The application user configured in the container. * `mariadb_password`: The application user password configured in the container. * `mariadb_root_password`: The root password configured in the container. * `mariadb_database`: The initial database configured in the container. The following version-specific fixtures are also available: * `mariadb_113_service`: MariaDB 11.3 * `mariadb_114_service`: MariaDB 11.4 LTS * `mariadb_122_service`: MariaDB 12.2 Rolling ``` -------------------------------- ### Service API: pytest_databases.docker.mssql.mssql_user() Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/sqlserver.md Returns the username for SQL Server authentication. ```APIDOC ### pytest_databases.docker.mssql.mssql_user() → str Returns the username for SQL Server authentication. ``` -------------------------------- ### Configure Pytest conftest.py Source: https://github.com/litestar-org/pytest-databases/blob/main/README.md Add the postgres fixture plugin to your pytest configuration file. ```python pytest_plugins = ["pytest_databases.docker.postgres"] ``` -------------------------------- ### MinIO Service API Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/minio.md The MinioService class provides access to MinIO service details like endpoint, access key, secret key, and security settings. It is typically provided by the `minio_service` fixture. ```APIDOC ## class pytest_databases.docker.minio.MinioService ### Description Provides access to MinIO service details. ### Attributes * **endpoint** (str) - The endpoint URL for the MinIO service. * **access_key** (str) - The access key for authenticating with MinIO. * **secret_key** (str) - The secret key for authenticating with MinIO. * **secure** (bool) - Indicates whether to use HTTPS for the MinIO connection. ``` -------------------------------- ### Enable PostgreSQL and Redis Plugins Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/getting-started/enabling-plugins.md Add these plugin paths to your pytest configuration to enable PostgreSQL and Redis support. ```python # Example: Enable PostgreSQL and Redis plugins pytest_plugins = [ "pytest_databases.docker.postgres", "pytest_databases.docker.redis", ] ``` -------------------------------- ### Use Postgres Fixture in Tests Source: https://github.com/litestar-org/pytest-databases/blob/main/README.md Inject the PostgresService fixture into your test function and use it to connect to the database. ```python 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 ``` -------------------------------- ### Service API: class pytest_databases.docker.mssql.MSSQLService Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/sqlserver.md Represents a SQL Server service running in a Docker container. ```APIDOC ### *class* pytest_databases.docker.mssql.MSSQLService(container: 'Container', host: 'str', port: 'int', user: 'str', password: 'str', database: 'str') Bases: `ServiceContainer` #### user *: str* #### password *: str* #### database *: str* #### *property* connection_string *: str* #### __init__(container: docker.models.containers.Container, host: str, port: int, user: str, password: str, database: str) → None ``` -------------------------------- ### RustfsService Class Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/rustfs.md Represents the RustFS service container, providing access to its endpoint, credentials, and security settings. ```APIDOC ## class pytest_databases.docker.rustfs.RustfsService Bases: `ServiceContainer` ### endpoint *: str* ### access_key *: str* ### secret_key *: str* ### secure *: bool* ### __init__(container: docker.models.containers.Container, host: str, port: int, endpoint: str, access_key: str, secret_key: str, secure: bool) -> None Initializes the RustfsService with connection details and credentials. ``` -------------------------------- ### Oracle Image and Service Name Fixtures Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/oracle.md Fixtures to retrieve the Docker image and service name for specific Oracle versions. ```APIDOC ## Fixtures: Oracle Image and Service Name ### `oracle_23ai_image()` Returns the Docker image name for Oracle 23ai. ### `oracle_23ai_service_name()` Returns the service name for Oracle 23ai. ### `oracle_18c_image()` Returns the Docker image name for Oracle 18c. ### `oracle_18c_service_name()` Returns the service name for Oracle 18c. ``` -------------------------------- ### Service API: pytest_databases.docker.mssql.xdist_mssql_isolation_level() Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/sqlserver.md Returns the Xdist isolation level for SQL Server. ```APIDOC ### pytest_databases.docker.mssql.xdist_mssql_isolation_level() → XdistIsolationLevel Returns the Xdist isolation level for SQL Server. ``` -------------------------------- ### Accessing Configuration in Tests Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/getting-started/configuration.md Demonstrates how to access configuration values like user, database, host, and port from a service fixture within a pytest test function. This is useful for verifying or using the active configuration settings. ```python from pytest_databases.docker.postgres import PostgresService def test_postgres_config_access(postgres_service: PostgresService) -> None: # Access configuration values used by the running service print(f"Connecting to Postgres user: {postgres_service.user}") print(f"Using database: {postgres_service.database}") print(f"On host: {postgres_service.host}:{postgres_service.port}") # Example assertions (replace with your expected defaults or env overrides) assert postgres_service.user == "postgres" assert postgres_service.password == "super-secret" assert postgres_service.database == "pytest_databases" assert postgres_service.host == "127.0.0.1" # Or your DOCKER_HOST override assert isinstance(postgres_service.port, int) assert postgres_service.port > 0 ``` -------------------------------- ### Yugabyte Fixtures Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/yugabyte.md Exposes various fixtures for managing and accessing Yugabyte DB services and configurations. ```APIDOC ## Available Fixtures * `yugabyte_image`: The Docker image to use for Yugabyte DB. * `yugabyte_user`: The Yugabyte user exposed on `yugabyte_service`. * `yugabyte_password`: The Yugabyte password exposed on `yugabyte_service`. * `yugabyte_database`: The database created for `yugabyte_service`. * `yugabyte_service`: A fixture that provides a Yugabyte DB service. * `xdist_yugabyte_isolation_level()`: Controls the isolation level for Yugabyte when using pytest-xdist. ``` -------------------------------- ### DoltService Class Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/dolt.md Represents a Dolt service instance, providing access to its connection details. ```APIDOC ## class pytest_databases.docker.dolt.DoltService Bases: ServiceContainer ### Attributes * **db**: The database name. * **user**: The application user. * **password**: The application user password. ### Methods * **__init__(container: docker.models.containers.Container, host: str, port: int, db: str, user: str, password: str)**: Initializes the DoltService. ``` -------------------------------- ### Dolt Fixtures Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/dolt.md Provides access to various fixtures for configuring and managing Dolt services within tests. ```APIDOC ### Available Fixtures * `dolt_service`: A fixture that provides a Dolt service (latest). * `dolt_user`: The application user configured in the container. * `dolt_password`: The application user password configured in the container. * `dolt_root_password`: The root password configured in the container. * `dolt_database`: The initial database configured in the container. ### pytest_databases.docker.dolt.xdist_dolt_isolation_level() -> Literal['database', 'server'] Configures the isolation level for xdist. Returns either 'database' or 'server'. ### pytest_databases.docker.dolt.platform() -> str Returns the platform string for the Dolt service. ### pytest_databases.docker.dolt.dolt_user() -> str Provides the Dolt application user. ### pytest_databases.docker.dolt.dolt_password() -> str Provides the Dolt application user password. ### pytest_databases.docker.dolt.dolt_root_password() -> str Provides the Dolt root password. ### pytest_databases.docker.dolt.dolt_database() -> str Provides the initial Dolt database name. ### pytest_databases.docker.dolt.dolt_service(...) -> Generator[[DoltService], None, None] Provides the Dolt service fixture, which yields a DoltService instance. It depends on several other fixtures for configuration. ``` -------------------------------- ### Set Custom PostgreSQL Host Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/postgres.md Configure the PostgreSQL container to use a specific host address. This is useful for connecting to a PostgreSQL instance on a particular network interface. ```bash export POSTGRES_HOST="192.168.1.100" pytest ``` -------------------------------- ### mongodb_service Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/mongodb.md Fixture that provides a configured MongoDBService instance. ```APIDOC ### pytest_databases.docker.mongodb.mongodb_service(docker_service: DockerService, xdist_mongodb_isolation_level: XdistIsolationLevel, mongodb_image: str) -> Generator[[MongoDBService], None, None] #### Description This fixture sets up and yields a MongoDBService instance, configured based on provided Docker service, isolation level, and image name. #### Yields * MongoDBService: An instance of the MongoDBService. ``` -------------------------------- ### Direct Database Interaction with PostgreSQL Connection Fixture Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/getting-started/basic-usage.md Utilize the `postgres_connection` fixture for direct access to a pre-configured database connection or client object to perform operations like table creation and data insertion. ```python # Example using the Connection Fixture def test_with_direct_connection(postgres_connection) -> None: # postgres_connection is often a configured client or connection object with postgres_connection.cursor() as cursor: cursor.execute("CREATE TABLE IF NOT EXISTS users (id INT PRIMARY KEY, name TEXT);") cursor.execute("INSERT INTO users (id, name) VALUES (1, 'Alice');") cursor.execute("SELECT name FROM users WHERE id = 1;") assert cursor.fetchone() == ('Alice',) ``` -------------------------------- ### Oracle Service Fixtures Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/oracle.md Fixtures to instantiate and manage Oracle database services for specific versions. ```APIDOC ## Fixtures: Oracle Services ### `oracle_23ai_service(docker_service: DockerService, oracle_23ai_image: str, oracle_23ai_service_name: str, oracle_user: str, oracle_password: str, oracle_system_password: str)` Provides a generator for an Oracle 23ai service instance. ### `oracle_18c_service(docker_service: DockerService, oracle_18c_image: str, oracle_18c_service_name: str, oracle_user: str, oracle_password: str, oracle_system_password: str)` Provides a generator for an Oracle 18c service instance. ### `oracle_service(oracle_23ai_service: OracleService)` An alias for the latest supported Oracle service, defaulting to `oracle_23ai_service`. ``` -------------------------------- ### Yugabyte Service API Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/yugabyte.md Provides access to a running Yugabyte DB service, including connection details and credentials. ```APIDOC ## class pytest_databases.docker.yugabyte.YugabyteService Bases: ServiceContainer Represents a Yugabyte DB service instance. ### Attributes * **database** (str): The database name for the Yugabyte service. * **user** (str): The username for connecting to the Yugabyte service. * **password** (str): The password for connecting to the Yugabyte service. * **host** (str): The host address of the Yugabyte service. * **port** (int): The port number of the Yugabyte service. ### Methods * **__init__(container: docker.models.containers.Container, host: str, port: int, database: str, user: str, password: str)**: Initializes the YugabyteService. ``` -------------------------------- ### Configure GizmoSQL Isolation for xdist Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/gizmosql.md Set the xdist isolation level for GizmoSQL to 'server'. This is the only supported isolation level for parallel testing with pytest-xdist. ```python @pytest.fixture(scope="session") def xdist_gizmosql_isolation_level(): return "server" # This is the only supported value ``` -------------------------------- ### mongodb_image Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/mongodb.md Provides the Docker image name for the MongoDB service. ```APIDOC ### pytest_databases.docker.mongodb.mongodb_image() #### Returns * str: The Docker image name for the MongoDB service (default: 'mongo:latest'). ``` -------------------------------- ### MongoDBService API Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/mongodb.md Provides details on the MongoDBService class and its attributes, which are essential for connecting to and interacting with a MongoDB instance managed by pytest-databases. ```APIDOC ## class pytest_databases.docker.mongodb.MongoDBService Bases: ServiceContainer ### Description Represents a running MongoDB service instance, providing connection details and management capabilities. ### Attributes * **username** (str): The username for authenticating with the MongoDB service. * **password** (str): The password for authenticating with the MongoDB service. * **database** (str): The name of the worker-specific database to use. ### Methods * **__init__(container: docker.models.containers.Container, host: str, port: int, username: str, password: str, database: str) -> None** Initializes the MongoDBService with connection parameters and a Docker container instance. ``` -------------------------------- ### Pin PostgreSQL Host Port Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/postgres.md Assign a specific host port to a PostgreSQL service, which can be a workaround for rootless Docker issues. This ensures a predictable port is used for the service. ```bash export PGVECTOR_18_PORT=5432 pytest tests/test_my_pgvector_thing.py ``` -------------------------------- ### Oracle Credential Fixtures Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/oracle.md Fixtures providing credentials for Oracle database access. ```APIDOC ## Fixtures: Oracle Credentials ### `oracle_user()` Returns the application username for the Oracle container. ### `oracle_password()` Returns the application user password for the Oracle container. ### `oracle_system_password()` Returns the system password for the Oracle container. ``` -------------------------------- ### OracleService Class Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/oracle.md The OracleService class provides access to connection details for an Oracle database container managed by pytest-databases. ```APIDOC ## Class: OracleService ### Description Provides connection metadata for an Oracle database container. ### Attributes * **user** (str): The application username. * **password** (str): The application user password. * **system_password** (str): The Oracle system password. * **service_name** (str): The Oracle service name. ### Methods * **__init__**(container: docker.models.containers.Container, host: str, port: int, user: str, password: str, system_password: str, service_name: str) -> None: Initializes the OracleService instance. ``` -------------------------------- ### xdist_mongodb_isolation_level Source: https://github.com/litestar-org/pytest-databases/blob/main/docs/supported-databases/mongodb.md Determines the isolation level for MongoDB services when using pytest-xdist. ```APIDOC ### pytest_databases.docker.mongodb.xdist_mongodb_isolation_level() #### Returns * Literal['database', 'server']: The isolation level for MongoDB services. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.