Pytest Configuration (Conftest)
Relevant source files
The following files were used as context for generating this wiki page:
The Pytest configuration for the flext-tap-oracle project provides a robust testing infrastructure designed to support unit, integration, and end-to-end (E2E) testing of a Singer Tap for Oracle. It leverages a lazy-loading architecture for test components and integrates deeply with Docker to provide ephemeral Oracle database instances for high-fidelity testing.
The configuration is managed through a combination of pyproject.toml settings, a central tests/conftest.py (referenced via lazy imports), and specialized fixture modules. This setup ensures that environment variables, database connections, and singleton settings are correctly isolated and reset between test executions, preventing cross-test pollution.
Sources: pyproject.toml:295-343, tests/init.py:76-105, tests/unit/fixtures.py:1-15
Test Execution Infrastructure
The testing suite is configured with specific plugins and options to optimize developer feedback and ensure strict compliance with project standards.
Pytest Options and Plugins
The project uses several Pytest extensions to enhance the testing workflow:
- pytest-xdist: Enables parallel test execution.
- pytest-cov: Provides coverage reporting, with a required minimum threshold of 20%.
- pytest-sugar: Improves the terminal output format.
- pytest-env: Manages environment variables during test sessions.
Sources: pyproject.toml:79-105, tool.pytest.ini_options:303-316
Test Markers
Tests are categorized using markers to allow selective execution based on the environment and requirements:
| Marker | Description |
|---|---|
unit | Standard unit tests for logic isolation. |
integration | Tests verifying interaction between internal components. |
docker | Tests requiring a running Docker daemon. |
e2e | End-to-end tests involving real database extraction. |
slow | Long-running tests excluded from fast feedback loops. |
Sources: pyproject.toml:325-336
Fixture Lifecycle and Environment Management
The project employs a tiered fixture system to manage the complex state required for Oracle database testing.
Oracle Container Management
For tests requiring a database, the system uses a shared Docker container. The lifecycle of this container is managed through the tk (ToolKit) control instance.
The shared_oracle_container fixture ensures the container is available and resolves the dynamic host port mapping for the Oracle listener.
Sources: tests/unit/fixtures.py:27-58, tests/constants.py:33-40
Settings Isolation and Resets
A critical aspect of the conftest logic is the prevention of singleton pollution. The reset_tap_oracle_settings fixture explicitly calls reset_for_testing() on both production and test settings classes.
@pytest.fixture(autouse=True)
def reset_tap_oracle_settings(reset_settings: None) -> Generator[None]:
"""Reset the concrete tap settings singletons around every test."""
_ = reset_settings
FlextTapOracleSettings.reset_for_testing()
TestsFlextTapOracleSettings.reset_for_testing()
try:
yield
finally:
FlextTapOracleSettings.reset_for_testing()
TestsFlextTapOracleSettings.reset_for_testing()
Sources: tests/unit/fixtures.py:91-105
Graceful Test Skipping (E2E)
To ensure tests can run in environments without Docker or Oracle access, the configuration includes a guardian fixture skip_e2e_if_no_oracle. This fixture attempts a socket connection to the configured Oracle host and port. If the connection fails and the test path contains /e2e/, the test is skipped with a descriptive message rather than failing.
Sources: tests/unit/fixtures.py:122-159, tests/constants.py:64-64
Lazy Loading and Test Facades
The test suite utilizes the flext_core.lazy mechanism to manage imports. This prevents heavy test utilities or dependencies from being loaded until they are explicitly required by a running test.
Test Component Mapping
The tests/__init__.py file establishes a mapping for the test facade, which includes:
- u (Utilities):
TestsFlextTapOracleUtilitiesproviding mock data generation and config creators. - m (Models):
TestsFlextTapOracleModelscontaining Pydantic entities for connections and streams. - c (Constants):
TestsFlextTapOracleConstantsdefining environment keys and default test values. - p (Protocols):
TestsFlextTapOracleProtocolsdefiningMockOracleConnectionandTestAssertionprotocols.
Sources: tests/init.py:55-121, tests/utilities.py:17-26, tests/protocols.py:20-33
Summary
The Pytest configuration in flext-tap-oracle provides a managed environment that balances the need for heavy integration testing (using Oracle containers) with the speed of unit testing. By centralizing environment variable injection, container orchestration, and singleton resets, the system ensures that the Singer Tap's complex state remains predictable and isolated across the entire test suite.