Test Fixtures
Relevant source files
The following files were used as context for generating this wiki page:
Test fixtures in the flext-tap-oracle project provide a structured environment for unit, integration, and end-to-end (E2E) testing. They manage lifecycle operations for Docker containers, environment variables, and configuration singletons to ensure test isolation and reproducibility. The system leverages pytest fixtures to orchestrate complex dependencies, such as live Oracle database instances and Singer protocol configurations.
Sources: tests/unit/fixtures.py:1-20, tests/utilities.py:10-25
Docker and Environment Orchestration
The project uses a tiered approach to manage external dependencies, primarily centering on an Oracle database container. The docker_control fixture provides an interface for container management, while subsequent fixtures ensure the container is running and accessible before tests proceed.
Container Lifecycle
The shared_oracle_container fixture manages the flext-oracle-db-test container. It resolves dynamic port mappings and injects connection details into the environment using an env_vars_context.
The diagram shows the sequence of checks and environment preparations performed by the container fixtures.
Sources: tests/unit/fixtures.py:28-60, tests/constants.py:26-35
Environment Variable Mapping
To support various test levels, specific environment variables are mapped from shared container constants to the standard Oracle environment keys.
| Environment Key | Fallback/Source Constant | Description |
|---|---|---|
ORACLE_HOST | SHARED_ORACLE_HOST_ENV | Hostname for DB connection |
ORACLE_PORT | SHARED_ORACLE_PORT_ENV | Mapped host port for the container |
ORACLE_USERNAME | SHARED_ORACLE_USER_ENV | Database user |
ORACLE_PASSWORD | SHARED_ORACLE_PASSWORD_ENV | Database password |
ORACLE_SERVICE_NAME | SHARED_ORACLE_SERVICE_ENV | Oracle service identifier |
Sources: tests/unit/fixtures.py:64-90, tests/constants.py:36-45
Settings and Singleton Management
A critical aspect of the test fixtures is the prevention of cross-test pollution. Because the project uses singleton patterns for configuration, fixtures are used to reset these singletons around every test execution.
Reset Mechanism
The reset_tap_oracle_settings fixture explicitly calls reset_for_testing() on both FlextTapOracleSettings and TestsFlextTapOracleSettings. This is necessary even if shared root fixtures exist, as model_validate failures can leave singletons in a partially initialized state.
The diagram illustrates the "sandwich" pattern used to clear configuration state before and after every test.
Sources: tests/unit/fixtures.py:93-110
Test Data and Mocking Infrastructure
The project defines protocols and utility classes to standardize how mock data is generated and validated across different test suites.
Mock Protocols
Protocols defined in tests/protocols.py ensure that mock objects used in fixtures adhere to the expected interfaces for Oracle connections and data providers.
- MockOracleConnection: Defines
connect,disconnect, andexecute_query. - TestDataProvider: Standardizes retrieval of test tables and mock records.
- TestAssertion: Provides reusable assertion logic for connection success and stream validity.
Sources: tests/protocols.py:44-110
Utility Helpers
The TestsFlextTapOracleUtilities class provides static methods used within fixtures to create standardized configurations and data.
# Example of utility usage within fixtures or tests
config = u.TapOracle.create_test_oracle_config(
host="test-oracle",
port=1521,
service_name="TESTDB"
)
Sources: tests/utilities.py:35-55, tests/constants.py:65-75
Execution Guards
Fixtures also act as quality gates, skipping tests when prerequisites are not met. The skip_e2e_if_no_oracle fixture performs a socket connection check. If a connection to the Oracle host/port cannot be established within a 0.5-second timeout, E2E tests are gracefully skipped to avoid long-running timeouts.
Sources: tests/unit/fixtures.py:126-155, tests/constants.py:62
Summary
The test fixture system in flext-tap-oracle provides a robust foundation for testing database integrations. By combining Docker orchestration, rigorous singleton resetting, and standardized mock protocols, it ensures that tests remain isolated and reliable. The use of utility mixins and constant namespaces further allows the test suite to scale while maintaining a single source of truth for test configurations.
Sources: tests/unit/fixtures.py:1-175, tests/utilities.py:10-30