Oracle#

Integration with Oracle AI Database (18c XE and 26ai Free) and Oracle Autonomous AI Database Free (adb-free:latest-26ai).

Installation#

pip install pytest-databases

Install oracledb in your project if your tests connect from the host. The service fixtures themselves validate readiness using sqlplus inside the container and do not require oracledb in the base package.

Usage Example#

import oracledb
from pytest_databases.docker.oracle import OracleService

pytest_plugins = ["pytest_databases.docker.oracle"]


def test(oracle_service: OracleService) -> None:
    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

Autonomous AI Database Free (26ai)#

oracle_adb_service starts the official container-registry.oracle.com/database/adb-free:latest-26ai container image, exposes all four Autonomous Database ports (1521 TLS, 1522 mTLS, 8443 ORDS / APEX / SQL Developer Web HTTPS, and 27017 Oracle Database API for MongoDB), provisions the test user via the ADMIN account on the DATA tablespace with DWROLE, REST-enables the schema via ORDS.ENABLE_SCHEMA, and automatically extracts the TLS/mTLS wallet to oracle_adb_service.wallet_dir with tnsnames.ora and sqlnet.ora rewritten for the mapped host and ports. A failure while provisioning the user or REST-enabling the schema fails the fixture with the SQL*Plus error. An unknown oracle_adb_workload_type raises ValueError. The container gets SYS_ADMIN and no devices by default; override oracle_adb_devices (for example ["/dev/fuse"]) when the container runtime host provides them.

The image’s server parameter file sets filesystemio_options to direct I/O, which cannot open the control files when the container storage has 4096-byte logical sectors (for example an overlay2 Docker root on a 4Kn or dm-crypt device): startup fails with ORA-27072 / ORA-00202 and then ORA-01034. oracle_adb_service therefore rewrites the server parameter file with filesystemio_options='NONE' before the image entrypoint starts the database (CREATE PFILE FROM SPFILE and CREATE SPFILE FROM PFILE against the idle instance, inside the container). NONE also works on 512-byte storage. Override oracle_adb_filesystemio_options to choose another value, or return None to start the image unchanged:

import pytest


@pytest.fixture(scope="session")
def oracle_adb_filesystemio_options() -> str | None:
    return None

The wallet and endpoints are available on the service:

from pathlib import Path
from pytest_databases.docker.oracle import OracleADBService, parse_tnsnames

pytest_plugins = ["pytest_databases.docker.oracle"]


def test_adb_wallet_and_endpoints(oracle_adb_service: OracleADBService, tmp_path: Path) -> None:
    assert oracle_adb_service.wallet_dir is not None
    assert oracle_adb_service.mtls_alias is not None
    assert oracle_adb_service.ca_cert_path is not None
    assert oracle_adb_service.ords_url.startswith("https://")
    assert oracle_adb_service.apex_url.endswith("/ords/apex")
    assert oracle_adb_service.sql_developer_url.endswith("/ords/sql-developer")
    assert "authMechanism=PLAIN" in oracle_adb_service.mongo_uri
    entries = parse_tnsnames((oracle_adb_service.wallet_dir / "tnsnames.ora").read_text(encoding="utf-8"))
    assert oracle_adb_service.mtls_alias in entries
    wallet_zip = oracle_adb_service.build_wallet_zip(
        tmp_path / "wallet.zip",
        wallet_password=oracle_adb_service.password,
    )
    assert wallet_zip.is_file()

mtls_alias selects the first *_high TCPS alias (or falls back to the first rewritten TCPS alias), and build_wallet_zip() archives host-mapped wallet artifacts (including cwallet.sso when include_sso=True and lazily synthesized PKCS#12 ewallet.p12 from ewallet.pem when optional cryptography is installed, omitting ewallet.p12 cleanly otherwise).

Parallel Execution#

By default, xdist_oracle_isolation_level returns "database". Under pytest-xdist, workers share one container per Oracle flavor (oracle26ai, oracle18c, and oracle_adb) and each worker receives an isolated user named <oracle_user>_<worker> (for example app_0 and app_1). Both single-process and pytest-xdist sessions provision the active user via ensure_oracle_user() under a cross-worker file lock with identical CONNECT, RESOURCE, and DBA roles plus QUOTA UNLIMITED ON USERS, idempotently tolerating ORA-01920 and retrying transient ORA-* startup or lock errors.

exec_sql(), exec_oracle_sql(), and public exec_sqlplus() run SQL or PL/SQL through in-container sqlplus against either a pluggable database service or CDB$ROOT (cdb_root=True / sqlplus -L -S / as sysdba). Custom fixtures calling provide_oracle_service() or provide_oracle_adb_service() can also pass host_port, env, volumes, shm_size, mem_limit, and one-shot init_sql scripts.

High-concurrency suites that open unpooled per-test connections against the shared container (for example, SQLAlchemy NullPool across large test suites without oracledb retry_count) can briefly exhaust TNS listener handlers and fail with ORA-12516 (DPY-6000). Resolve listener contention using either of the following options:

  1. Enable connection pooling instead of NullPool, or configure oracledb retry_count and retry_delay in your driver connection arguments so transient listener refusals retry automatically.

  2. Override xdist_oracle_isolation_level to return "server" so each worker runs a dedicated transient container and listener (at higher memory and startup cost):

import pytest
from pytest_databases.types import XdistIsolationLevel


@pytest.fixture(scope="session")
def xdist_oracle_isolation_level() -> XdistIsolationLevel:
    return "server"

Available Fixtures#

  • oracle_user: The application username created in the Oracle container (default: "app", env ORACLE_USER).

  • oracle_password: The application user password (default: "super-secret", env ORACLE_PASSWORD).

  • oracle_system_password: The Oracle system password (default: "super-secret", env ORACLE_SYSTEM_PASSWORD).

  • oracle_port: Optional pinned host port for the default Oracle container (default: None, env ORACLE_PORT).

  • xdist_oracle_isolation_level: Worker isolation mode: "database" (default, shared container with per-worker users) or "server" (one transient container per worker).

  • oracle_startup_timeout: Startup timeout in seconds for oracle_18c_service and oracle_26ai_service (default 180, env ORACLE_STARTUP_TIMEOUT; non-integer or non-positive values raise ValueError).

  • oracle_adb_startup_timeout: Startup timeout in seconds for oracle_adb_service (default 420, env ORACLE_ADB_STARTUP_TIMEOUT; non-integer or non-positive values raise ValueError).

  • oracle_service: Alias for the latest supported Oracle service (oracle_26ai_service).

The following version-specific and Autonomous Database fixtures are also available:

  • oracle_18c_image, oracle_18c_service_name, oracle_18c_port (env ORACLE_18C_PORT), oracle_18c_service: Oracle 18c XE

  • oracle_26ai_image (default gvenzl/oracle-free:23-slim-faststart, delivering the 23.26.x Oracle AI Database 26ai Free release line; env ORACLE_26AI_IMAGE), oracle_26ai_service_name (default FREEPDB1, env ORACLE_26AI_SERVICE_NAME), oracle_26ai_port (env ORACLE_26AI_PORT, falling back to oracle_port), oracle_26ai_service: Oracle AI Database 26ai Free. The v0.19.0 oracle_23ai_image, oracle_23ai_service_name, oracle_23ai_service, and oracle_23ai_connection fixtures (and external overrides of oracle_23ai_image, oracle_23ai_service_name, and oracle_23ai_service) remain available as deprecated aliases until v1.0.0.

  • oracle_adb_image, oracle_adb_workload_type (ATP, ADW, AJD, APEX), oracle_adb_hostname, oracle_adb_tz, oracle_adb_password, oracle_adb_admin_password, oracle_adb_wallet_password, oracle_adb_wallet_dir, oracle_adb_volumes, oracle_adb_devices, oracle_adb_filesystemio_options (default NONE, env ORACLE_ADB_FILESYSTEMIO_OPTIONS), oracle_adb_port (env ORACLE_ADB_PORT), oracle_adb_service: Oracle Autonomous AI Database Free (26ai)

Service API#

Oracle Database and Autonomous Database Free container fixtures and wallet helpers.

class pytest_databases.docker.oracle.OracleADBService(container: docker.models.containers.Container, host: str, port: int, user: str, password: str, system_password: str, service_name: str, tls_port: int, wallet_password: str, workload_type: str, service_names: tuple[str, ...], ords_port: int = 8443, mongo_port: int = 27017, wallet_dir: Path | None = None)[source]#

Bases: OracleService

Container handle for Oracle Autonomous Database Free with TLS/mTLS wallet, ORDS, and MongoDB API support.

tls_port: int#
wallet_password: str#
workload_type: str#
service_names: tuple[str, ...]#
ords_port: int = 8443#
mongo_port: int = 27017#
wallet_dir: Path | None = None#
property ca_cert_path: Path | None#

Path to the extracted adb_container.cert CA certificate when wallet_dir is populated.

property ords_url: str#

HTTPS base URL for Oracle REST Data Services (ORDS).

property apex_url: str#

HTTPS URL for Oracle APEX inside the ADB-Free container.

property sql_developer_url: str#

HTTPS URL for Oracle SQL Developer Web (Database Actions).

property mongo_uri: str#

MongoDB API connection URI for the ADB-Free container on mongo_port.

extract_wallet(target_dir: Path) → Path[source]#

Extract the container wallet files into target_dir and rewrite tnsnames.ora and sqlnet.ora.

enable_ords_schema(schema: str | None = None, *, url_mapping_pattern: str | None = None, auto_rest_auth: bool = False) → None[source]#

REST-enable schema (defaults to self.user) for ORDS, SQL Developer Web, and MongoDB API.

property mtls_alias: str | None#

Preferred TCPS TNS alias from wallet_dir/tnsnames.ora, if available.

build_wallet_zip(target_path: str | Path, *, include_sso: bool = True, wallet_password: str | None = None) → Path[source]#

Bundle extracted ADB wallet files into a ZIP archive at target_path.

When ewallet.p12 is absent and ewallet.pem exists, lazily synthesizes an encrypted PKCS#12 ewallet.p12 bundle using cryptography if installed.

Parameters:
  • target_path – Destination ZIP archive path.

  • include_sso – Whether to include cwallet.sso in the archive.

  • wallet_password – Optional password override used to encrypt synthesized ewallet.p12.

Returns:

Resolved Path of the written ZIP archive.

Raises:

RuntimeError – If wallet_dir is unset or does not exist on disk.

__init__(container: docker.models.containers.Container, host: str, port: int, user: str, password: str, system_password: str, service_name: str, tls_port: int, wallet_password: str, workload_type: str, service_names: tuple[str, ...], ords_port: int = 8443, mongo_port: int = 27017, wallet_dir: Path | None = None) → None#
class pytest_databases.docker.oracle.OracleService(container: docker.models.containers.Container, host: str, port: int, user: str, password: str, system_password: str, service_name: str)[source]#

Bases: ServiceContainer

Container handle with administrative and application credentials for Oracle.

user: str#
password: str#
system_password: str#
service_name: str#
exec_sql(sql: str, *, user: str | None = None, password: str | None = None, service_name: str | None = None, as_sysdba: bool = False, cdb_root: bool = False, whenever_sqlerror: str = 'EXIT SQL.SQLCODE', retry_transient: bool = False) → tuple[int, bytes][source]#

Execute sql via in-container sqlplus against this Oracle service.

Parameters:
  • sql – SQL statement or PL/SQL script to run.

  • user – Optional login override (defaults to "sys" when as_sysdba is set, else self.user).

  • password – Optional password override (defaults to system_password for administrative execution).

  • service_name – Optional TNS/PDB service override (defaults to self.service_name).

  • as_sysdba – Connect with AS SYSDBA administrative privileges over TNS.

  • cdb_root – Connect directly to CDB$ROOT via OS authentication (sqlplus -L -S / as sysdba).

  • whenever_sqlerror – SQL*Plus WHENEVER SQLERROR directive.

  • retry_transient – Retry boundedly on transient listener/startup/catalog lock errors.

Returns:

Tuple of (exit_code, output_bytes).

__init__(container: docker.models.containers.Container, host: str, port: int, user: str, password: str, system_password: str, service_name: str) → None#
pytest_databases.docker.oracle.enable_oracle_ords_schema(container: docker.models.containers.Container, user: str, password: str, service_name: str, *, url_mapping_pattern: str | None = None, auto_rest_auth: bool = False) → None[source]#

REST-enable an Oracle Autonomous Database schema for ORDS, SQL Developer Web, and MongoDB API.

Parameters:
  • container – Running Oracle ADB-Free container.

  • user – Database schema owner username.

  • password – User password.

  • service_name – Autonomous Database service name.

  • url_mapping_pattern – Optional URL mapping slug (defaults to user.lower()).

  • auto_rest_auth – Whether to require authentication on auto-REST metadata endpoints.

Raises:

RuntimeError – If ORDS.ENABLE_SCHEMA fails.

pytest_databases.docker.oracle.ensure_oracle_adb_user(container: docker.models.containers.Container, user: str, password: str, service_name: str, admin_password: str) → None[source]#

Provision an Oracle Autonomous Database application user via the ADMIN account.

An existing user (ORA-01920) gets its password reset instead of being recreated; ORA-28007 from that reset (the ADB password profile rejects reusing the current password) is ignored because the password is already correct. Any other error stops the script.

Parameters:
  • container – Running Oracle ADB-Free container.

  • user – Application username to create or update.

  • password – Password meeting CLOUD_VERIFY_FUNCTION complexity rules.

  • service_name – Autonomous Database service name (e.g. myatp_high.adb.oraclecloud.com).

  • admin_password – Password for the ADMIN administrative account.

Raises:

RuntimeError – If creating, unlocking, or granting privileges to the user fails.

pytest_databases.docker.oracle.ensure_oracle_user(container: docker.models.containers.Container, user: str, password: str, service_name: str, system_password: str) → bool[source]#

Ensure an Oracle application user exists with appropriate tablespace quota and roles.

Existing users (ORA-01920) have their password synchronized (tolerating ORA-28007 when password-reuse rules reject the current password) and unlocked before applying grants and tablespace quota. Transient Oracle startup, listener, or lock errors are retried via _run_sqlplus_with_retry.

Parameters:
  • container – The container instance.

  • user – Effective username to create.

  • password – User password.

  • service_name – Oracle service or PDB name.

  • system_password – SYS administrative user password.

Returns:

True if the SQL*Plus provisioning command exited cleanly.

pytest_databases.docker.oracle.exec_oracle_sql(container: docker.models.containers.Container, sql: str, *, service_name: str | None = None, user: str | None = None, password: str | None = None, as_sysdba: bool = False, whenever_sqlerror: str = 'EXIT SQL.SQLCODE', retry_transient: bool = False) → tuple[int, bytes][source]#

Execute SQL or PL/SQL inside a running Oracle container via sqlplus.

Supports both TNS service/PDB execution (user/password@//localhost:1521/service) and OS-authenticated CDB$ROOT execution (sqlplus -L -S / as sysdba when as_sysdba=True and service_name, user, and password are omitted). Modulo-256 zero exit codes on ORA-/PLS-/SP2- errors are normalized to 1 unless whenever_sqlerror="CONTINUE".

Parameters:
  • container – Running Oracle container handle.

  • sql – SQL statement or PL/SQL block.

  • service_name – Target PDB or service name (omit with as_sysdba=True for CDB$ROOT).

  • user – Database username (omit with as_sysdba=True for OS authentication).

  • password – User password.

  • as_sysdba – Connect with AS SYSDBA administrative privileges.

  • whenever_sqlerror – SQL*Plus WHENEVER SQLERROR directive.

  • retry_transient – Retry boundedly on transient listener, startup, or catalog lock errors.

Returns:

Tuple of (exit_code, output_bytes).

Raises:

ValueError – If TNS execution is missing service_name, user, or password.

pytest_databases.docker.oracle.exec_sqlplus(container: docker.models.containers.Container, sql: str, *, connect_as: str = '/ as sysdba', whenever_sqlerror: str = 'EXIT SQL.SQLCODE') → tuple[int, str][source]#

Execute SQL or PL/SQL inside an Oracle container via sqlplus and decode the output.

Supports both OS authentication (default "/ as sysdba") and explicit credential strings such as "user/password@//127.0.0.1:1521/FREEPDB1". Modulo-256 zero exit codes with ORA-/PLS-/SP2- output errors are normalized to 1.

Parameters:
  • container – Running Oracle container handle.

  • sql – SQL statement or PL/SQL block.

  • connect_as – SQL*Plus connection specifier.

  • whenever_sqlerror – SQL*Plus WHENEVER SQLERROR directive.

Returns:

Tuple of (exit_code, decoded_output).

Raises:

ValueError – If connect_as is empty or whitespace-only.

pytest_databases.docker.oracle.extract_adb_wallet(container: docker.models.containers.Container, target_dir: Path, *, host: str, port: int, tls_port: int | None = None, container_wallet_path: str = '/u01/app/oracle/wallets/tls_wallet') → Path[source]#

Extract the TLS/mTLS wallet directory from an Oracle ADB-Free container and rewrite tnsnames.ora and sqlnet.ora.

Parameters:
  • container – Running Oracle ADB-Free container.

  • target_dir – Destination host directory where wallet files will be written.

  • host – Mapped container host address.

  • port – Mapped port for internal port 1521.

  • tls_port – Optional mapped port for internal port 1522.

  • container_wallet_path – Path to the wallet directory inside the container.

Returns:

Path to target_dir containing extracted wallet files (cwallet.sso, ewallet.p12, ewallet.pem, keystore.jks, truststore.jks, ojdbc.properties, adb_container.cert, tnsnames.ora, sqlnet.ora).

pytest_databases.docker.oracle.oracle_18c_connection(oracle_18c_service: OracleService) → Generator[Any, None, None][source]#

Deprecated oracledb connection fixture for Oracle 18c XE.

Yields:

An open oracledb.Connection.

pytest_databases.docker.oracle.oracle_18c_image() → str[source]#

Container image for Oracle Database 18c XE.

pytest_databases.docker.oracle.oracle_18c_port() → int | None[source]#

Optional pinned host port for Oracle 18c XE (ORACLE_18C_PORT).

pytest_databases.docker.oracle.oracle_18c_service(docker_service: DockerService, xdist_oracle_isolation_level: XdistIsolationLevel, oracle_18c_image: str, oracle_18c_service_name: str, oracle_user: str, oracle_password: str, oracle_system_password: str, oracle_startup_timeout: int, oracle_18c_port: int | None) → Generator[OracleService, None, None][source]#

Session fixture providing an Oracle Database 18c XE container service.

Yields:

An OracleService handle.

pytest_databases.docker.oracle.oracle_18c_service_name() → str[source]#

Default PDB service name for Oracle Database 18c XE.

pytest_databases.docker.oracle.oracle_23ai_connection(request: pytest.FixtureRequest) → Generator[Any, None, None][source]#

Deprecated oracledb connection fixture preserved for v0.19.0 callers.

Deprecated since version 0.20.0: Create an oracledb connection from oracle_service or oracle_26ai_service instead. oracle_23ai_connection will be removed in v1.0.0.

Yields:

An open oracledb.Connection.

pytest_databases.docker.oracle.oracle_23ai_image() → str[source]#

Deprecated alias for oracle_26ai_image preserved for v0.19.0 callers.

Deprecated since version 0.20.0: Use oracle_26ai_image instead. oracle_23ai_image will be removed in v1.0.0.

pytest_databases.docker.oracle.oracle_23ai_service(oracle_26ai_service: OracleService) → OracleService[source]#

Deprecated alias for oracle_26ai_service preserved for v0.19.0 callers.

Deprecated since version 0.20.0: Use oracle_26ai_service or oracle_service instead. oracle_23ai_service will be removed in v1.0.0.

pytest_databases.docker.oracle.oracle_23ai_service_name() → str[source]#

Deprecated alias for oracle_26ai_service_name preserved for v0.19.0 callers.

Deprecated since version 0.20.0: Use oracle_26ai_service_name instead. oracle_23ai_service_name will be removed in v1.0.0.

pytest_databases.docker.oracle.oracle_26ai_connection(oracle_26ai_service: OracleService) → Generator[Any, None, None][source]#

Deprecated oracledb connection fixture for Oracle AI Database 26ai Free.

Yields:

An open oracledb.Connection.

pytest_databases.docker.oracle.oracle_26ai_image(request: FixtureRequest) → str[source]#

Container image for Oracle AI Database 26ai Free (23.26.x track on gvenzl/oracle-free).

pytest_databases.docker.oracle.oracle_26ai_port(oracle_port: int | None) → int | None[source]#

Optional pinned host port for Oracle AI Database 26ai Free (ORACLE_26AI_PORT or ORACLE_PORT).

pytest_databases.docker.oracle.oracle_26ai_service(docker_service: DockerService, xdist_oracle_isolation_level: XdistIsolationLevel, oracle_26ai_image: str, oracle_26ai_service_name: str, oracle_user: str, oracle_password: str, oracle_system_password: str, oracle_startup_timeout: int, oracle_26ai_port: int | None) → Generator[OracleService, None, None][source]#

Session fixture providing an Oracle AI Database 26ai Free container service.

Yields:

An OracleService handle.

pytest_databases.docker.oracle.oracle_26ai_service_name(request: FixtureRequest) → str[source]#

Default PDB service name for Oracle AI Database 26ai Free.

pytest_databases.docker.oracle.oracle_adb_admin_password() → str[source]#

Administrative ADMIN password for Oracle Autonomous Database Free.

pytest_databases.docker.oracle.oracle_adb_devices() → list[str] | None[source]#

Optional device mappings for Oracle Autonomous Database Free, such as ["/dev/fuse"].

The devices must exist on the container runtime host, which is not necessarily the host running pytest.

pytest_databases.docker.oracle.oracle_adb_filesystemio_options() → str | None[source]#

filesystemio_options written to the ADB-Free server parameter file before the database starts.

Defaults to NONE (env ORACLE_ADB_FILESYSTEMIO_OPTIONS) so the instance opens on storage with 4096-byte logical sectors. Override this fixture to return None to keep the image’s own setting.

pytest_databases.docker.oracle.oracle_adb_hostname() → str[source]#

Container hostname for Oracle Autonomous Database Free.

pytest_databases.docker.oracle.oracle_adb_image() → str[source]#

Container image for Oracle Autonomous AI Database Free (26ai).

pytest_databases.docker.oracle.oracle_adb_password() → str[source]#

Application password for Oracle Autonomous Database Free (meets CLOUD_VERIFY_FUNCTION rules).

pytest_databases.docker.oracle.oracle_adb_port() → int | None[source]#

Optional pinned host port for Oracle ADB-Free (ORACLE_ADB_PORT).

pytest_databases.docker.oracle.oracle_adb_service(docker_service: DockerService, xdist_oracle_isolation_level: XdistIsolationLevel, oracle_adb_image: str, oracle_adb_workload_type: str, oracle_adb_hostname: str, oracle_adb_tz: str, oracle_user: str, oracle_adb_password: str, oracle_adb_admin_password: str, oracle_adb_wallet_password: str, oracle_adb_wallet_dir: Path, oracle_adb_volumes: dict[str, dict[str, str]] | list[str] | None, oracle_adb_devices: list[str] | None, oracle_adb_filesystemio_options: str | None, oracle_adb_startup_timeout: int, oracle_adb_port: int | None) → Generator[OracleADBService, None, None][source]#

Session fixture providing an Oracle Autonomous AI Database Free (26ai) container service.

Yields:

An OracleADBService handle.

pytest_databases.docker.oracle.oracle_adb_startup_timeout() → int[source]#

Startup timeout in seconds for Oracle Autonomous AI Database Free containers.

pytest_databases.docker.oracle.oracle_adb_tz() → str[source]#

Database timezone (MY_TZ) for Oracle Autonomous Database Free.

pytest_databases.docker.oracle.oracle_adb_volumes() → dict[str, dict[str, str]] | list[str] | None[source]#

Optional volume mounts for Oracle Autonomous Database Free.

pytest_databases.docker.oracle.oracle_adb_wallet_dir(tmp_path_factory: TempPathFactory) → Path[source]#

Host directory where the Oracle Autonomous Database Free wallet is extracted.

pytest_databases.docker.oracle.oracle_adb_wallet_password() → str[source]#

Wallet password for Oracle Autonomous Database Free (meets CLOUD_VERIFY_FUNCTION rules).

pytest_databases.docker.oracle.oracle_adb_workload_type() → str[source]#

Workload type for Oracle Autonomous Database Free (ATP, ADW, AJD, or APEX).

pytest_databases.docker.oracle.oracle_password() → str[source]#

Default application password for Oracle.

pytest_databases.docker.oracle.oracle_port() → int | None[source]#

Optional pinned host port for the default Oracle container (ORACLE_PORT).

pytest_databases.docker.oracle.oracle_responsive(host: str, port: int, service_name: str, user: str, password: str) → bool[source]#

Check whether an Oracle instance responds to a SELECT 1 FROM dual query via oracledb.

Deprecated since version 0.20.0: oracle_responsive is deprecated in v0.20.0 and will be removed in v1.0.0.

Returns:

True when the query returns 1, otherwise False.

pytest_databases.docker.oracle.oracle_service(request: FixtureRequest) → OracleService[source]#

Alias for the latest default Oracle service (26ai).

pytest_databases.docker.oracle.oracle_startup_connection(oracle_26ai_service: OracleService) → Generator[Any, None, None][source]#

Deprecated alias for oracle_26ai_connection preserved for v0.19.0 callers.

Yields:

An open oracledb.Connection.

pytest_databases.docker.oracle.oracle_startup_timeout() → int[source]#

Startup timeout in seconds for Oracle Database 18c and 26ai containers.

pytest_databases.docker.oracle.oracle_system_password() → str[source]#

Default administrative SYS password for Oracle.

pytest_databases.docker.oracle.oracle_user() → str[source]#

Default application username for Oracle.

pytest_databases.docker.oracle.parse_tnsnames(tns_content: str) → dict[str, dict[str, str]][source]#

Parse an Oracle tnsnames.ora file into structured service descriptor dictionaries.

Parameters:

tns_content – Raw text content of tnsnames.ora.

Returns:

Mapping of lowercase TNS alias names to dictionaries containing protocol, host, port, service_name, and descriptor.

pytest_databases.docker.oracle.provide_oracle_adb_service(docker_service: DockerService, image: str, name: str, workload_type: str, hostname: str, user: str, password: str, system_password: str, wallet_password: str, isolation_level: XdistIsolationLevel = 'database', *, tz: str = 'UTC', host_port: int | None = None, env: Mapping[str, str] | None = None, wallet_dir: Path | None = None, volumes: dict[str, dict[str, str]] | list[str] | None = None, devices: list[str] | None = None, shm_size: int | str | None = None, mem_limit: str | None = None, init_sql: str | Path | Sequence[str | Path] | None = None, filesystemio_options: str | None = 'NONE', timeout: int = 420, pause: float = 2.0) → Generator[OracleADBService, None, None][source]#

Start and manage an Oracle Autonomous AI Database Free (26ai) container.

The image’s server parameter file sets filesystemio_options to direct I/O, which cannot open the control files when the container storage has 4096-byte logical sectors (ORA-27072, ORA-00202, then ORA-01034). By default the container command therefore rewrites the server parameter file with filesystemio_options='NONE' (CREATE PFILE FROM SPFILE and CREATE SPFILE FROM PFILE against the idle instance) and then runs the image entrypoint. Pass filesystemio_options=None to start the image unchanged.

Parameters:
  • docker_service – The container service manager.

  • image – Oracle ADB-Free container image.

  • name – Logical container service name.

  • workload_type – Autonomous workload profile (ATP, ADW, AJD, or APEX).

  • hostname – Container hostname required by ADB-Free initialization scripts.

  • user – Default application username.

  • password – Application user password meeting CLOUD_VERIFY_FUNCTION rules.

  • system_password – ADMIN account password.

  • wallet_password – Password protecting the container’s TLS/mTLS wallet.

  • isolation_level – xdist isolation strategy (database or server).

  • tz – Database timezone passed via MY_TZ (defaults to UTC).

  • host_port – Optional pinned host TCP port for listener port 1521.

  • env – Optional extra container environment variables merged over defaults.

  • wallet_dir – Optional host directory where the container wallet will be extracted automatically.

  • volumes – Optional container volume mounts (e.g. for /u01/app/oracle/wallets/tls_wallet).

  • devices – Optional device mappings for the container runtime host (for example ["/dev/fuse"]).

  • shm_size – Optional /dev/shm size forwarded to container creation.

  • mem_limit – Optional container memory limit forwarded to container creation.

  • init_sql – Optional SQL/PLSQL statement, file path, or sequence executed once per target user/service.

  • filesystemio_options – filesystemio_options value written to the server parameter file before the database starts (NONE, ASYNC, DIRECTIO, or SETALL), or None for the image default.

  • timeout – Maximum startup wait time in seconds.

  • pause – Sleep interval in seconds between readiness polling attempts.

Yields:

An OracleADBService handle configured for the active worker.

Raises:

ValueError – If workload_type is not ATP, ADW, AJD, or APEX, filesystemio_options is not a valid filesystemio_options value, timeout is not a positive integer, or pause is not a positive finite number.

pytest_databases.docker.oracle.provide_oracle_service(docker_service: DockerService, image: str, name: str, service_name: str, user: str, password: str, system_password: str, isolation_level: XdistIsolationLevel = 'database', *, host_port: int | None = None, env: Mapping[str, str] | None = None, volumes: dict[str, dict[str, str]] | list[str] | None = None, shm_size: int | str | None = None, mem_limit: str | None = None, init_sql: str | Path | Sequence[str | Path] | None = None, timeout: int = 180, pause: float = 1.0) → Generator[OracleService, None, None][source]#

Start and manage an Oracle database container with consistent privilege provisioning.

Both single-process and pytest-xdist runs run ensure_oracle_user() against effective_user so APP_USER always receives identical CONNECT, RESOURCE, DBA, and QUOTA UNLIMITED ON USERS privileges regardless of concurrency mode.

Parameters:
  • docker_service – The container service manager.

  • image – Container image for Oracle.

  • name – Logical container service name.

  • service_name – Oracle PDB or service name.

  • user – Default application username.

  • password – Application user password.

  • system_password – Administrative SYS password.

  • isolation_level – xdist isolation strategy (database or server).

  • host_port – Optional pinned host TCP port for listener port 1521.

  • env – Optional extra container environment variables merged over defaults.

  • volumes – Optional container volume mounts.

  • shm_size – Optional /dev/shm size (important for larger Oracle SGA configurations).

  • mem_limit – Optional container memory limit (for example "4g").

  • init_sql – Optional SQL/PLSQL statement, file path, or sequence executed once per target user/PDB.

  • timeout – Maximum startup wait time in seconds.

  • pause – Sleep interval in seconds between readiness polling attempts.

Yields:

An OracleService handle configured for the active worker.

Raises:

ValueError – If timeout is not a positive integer or pause is not a positive finite number.

pytest_databases.docker.oracle.rewrite_sqlnet_ora(sqlnet_content: str, wallet_dir: Path) → str[source]#

Rewrite sqlnet.ora WALLET_LOCATION DIRECTORY to wallet_dir and disable DN matching.

Parameters:
  • sqlnet_content – Original sqlnet.ora content.

  • wallet_dir – Host directory containing the extracted wallet files.

Returns:

Updated sqlnet.ora text.

pytest_databases.docker.oracle.rewrite_tnsnames(tns_content: str, *, host: str, port: int, tls_port: int | None = None) → str[source]#

Rewrite HOST, PORT, and SSL_SERVER_DN_MATCH entries in tnsnames.ora for host access.

Parameters:
  • tns_content – Original tnsnames.ora content.

  • host – Mapped host address.

  • port – Mapped host port for internal port 1521.

  • tls_port – Optional mapped host port for internal mTLS port 1522.

Returns:

Updated tnsnames.ora text.

pytest_databases.docker.oracle.xdist_oracle_isolation_level() → XdistIsolationLevel[source]#

Determine Oracle xdist isolation mode (database or server).