Test Configuration Overrides
Relevant source files
The following files were used as context for generating this wiki page:
Test Configuration Overrides in the flext-tap-oracle project provide a mechanism to inject environment-specific settings and mock data during automated testing. This system ensures that tests—ranging from unit tests to end-to-end (E2E) integration tests involving Docker containers—operate within a controlled environment without polluting production configurations.
The architecture relies on the FlextTapOracleSettings class for runtime management and specialized test classes like TestsFlextTapOracleSettings for override management. It utilizes Pytest fixtures to reset singletons and manage environment variables, ensuring high isolation between test cases. Sources: src/flext_tap_oracle/settings.py:19-22, tests/unit/fixtures.py:91-105
Settings Architecture and Inheritance
The project follows a tiered configuration model where test settings inherit from production settings but apply specific overrides through Pydantic's env_prefix and context-managed environment variables.
Configuration Hierarchy
Test models like TestsFlextTapOracleModels and TestsFlextTapOracleSettings use composition and inheritance to extend the base functionality of the Oracle Tap.
The diagram shows the inheritance relationship between core FLEXT settings, the Oracle Tap implementation, and the test-specific overrides.
Sources: src/flext_tap_oracle/settings.py:22-25, tests/models.py:20-30
Environment Variable Injection
Tests utilize a env_vars_context utility to temporarily override configuration values. This is critical for pointing the tap to dynamic ports assigned by Docker containers during CI/CD or local execution.
| Environment Variable | Description | Test Default |
|---|---|---|
FLEXT_TAP_ORACLE_ORACLE_HOST | Target Oracle Host | localhost |
FLEXT_TAP_ORACLE_ORACLE_PORT | Target Oracle Port | 1522 (Docker) |
ORACLE_TAP_TEST_MODE | Flags the tap as running in test mode | true |
FLEXT_LOG_LEVEL | Logging verbosity for the framework | DEBUG |
Sources: tests/constants.py:30-45, tests/unit/fixtures.py:46-53
Lifecycle of a Test Override
When a test requires a specific configuration (e.g., a custom batch size), the following sequence occurs:
This sequence ensures that configuration state does not persist across different test modules.
Sources: tests/unit/fixtures.py:91-105, src/flext_tap_oracle/settings.py:112-120
Oracle Tap Discovery and Sync Rules
The project defines strict validation rules for Oracle connections within rules.json. Test overrides must adhere to these constraints to pass validation during configuration instantiation.
Connection Rules Summary
- Required Fields:
host,username,password. - Conditional Requirement: Either
service_nameorsidmust be provided. - Default Port: 1521 (Production), 1522 (Test Default).
- Batch Size Limits: Minimum 1, Maximum 50,000.
Sources: src/flext_tap_oracle/rules.json:71-80, src/flext_tap_oracle/rules.json:101-110
Test Data and Mock Utilities
The TapOracle namespace within TestsFlextTapOracleUtilities provides methods to generate configuration objects and mock data rows programmatically, facilitating reproducible test scenarios.
Key Utility Functions
create_test_oracle_config: Generates a dictionary containing standard Oracle connection parameters.create_test_singer_stream: Produces a mock Singer stream configuration for replication testing.generate_mock_oracle_data: Creates a sequence of mock records for simulating database extraction.
Sources: tests/utilities.py:44-55, tests/utilities.py:85-95
# Example of utility usage for override generation
config = u.TapOracle.create_test_oracle_config(
host="test-oracle",
batch_size=c.TapOracle.Tests.UNIT_BATCH_SIZE
)
Sources: tests/utilities.py:56-65, tests/constants.py:65
Resilience and Cleanup
To prevent cross-test pollution, the reset_tap_oracle_settings fixture explicitly calls reset_for_testing() on both the production and test settings singletons. This is mandatory because Pydantic model validation failures can leave singletons in a partially initialized state. Sources: tests/unit/fixtures.py:91-105
Additionally, the skip_e2e_if_no_oracle fixture performs a socket check against the configured host and port. If the Oracle database (defined by the overrides) is unreachable, the test is skipped gracefully rather than failing, which is essential for environments without Docker support. Sources: tests/unit/fixtures.py:122-152
Conclusion
Test Configuration Overrides in flext-tap-oracle provide a robust framework for simulating Oracle database environments. By combining Pydantic validation, explicit singleton management, and environment variable masking, the project maintains high reliability in its integration and unit testing suites.