Environment Settings
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Environment Settings in the flext-tests ecosystem manage the configuration, isolation, and validation of test runtimes. The system utilizes FlextSettings and FlextTestsSettings to define project-wide and test-specific behaviors. It ensures that configuration state is correctly initialized, isolated between test runs, and validated against architectural standards.
The configuration architecture relies on pyproject.toml as the primary source of metadata and static settings, while dynamic runtime settings are handled through a singleton pattern with built-in reset mechanisms for testing environments.
Sources: README.md:21-23, src/flext_tests/_fixtures/settings.py:12-21
Settings Architecture and Life Cycle
The settings system is built around a singleton management pattern that ensures a clean state for every test execution. This is primarily handled through the _reset_runtime_state function and associated pytest fixtures.
Runtime Reset Logic
The system enforces a "zero-debt" baseline by resetting three core components before and after each test:
- FlextSettings: Root configuration singleton.
- FlextTestsSettings: Test-specific configuration singleton.
- FlextContainer: Dependency Injection (DI) container.
The diagram shows the lifecycle of settings during a single test run, ensuring isolation.
Sources: src/flext_tests/_fixtures/settings.py:32-37, src/flext_tests/_fixtures/settings.py:68-73
Key Classes and Functions
| Component | Description |
|---|---|
FlextTestsSettings | Typed settings class for test-specific configurations (e.g., debug, trace). |
_reset_runtime_state() | Internal utility to clear singletons for FlextSettings, FlextTestsSettings, and FlextContainer. |
pytest_runtest_setup() | Hook that triggers reset and alias binding before each test. |
settings fixture | Provides a fresh FlextTestsSettings instance with debug=True. |
settings_factory fixture | Allows creation of project-specific settings with specific overrides. |
Sources: src/flext_tests/_fixtures/settings.py:32-37, src/flext_tests/_fixtures/settings.py:102-110, src/flext_tests/_fixtures/settings.py:113-118
Configuration Validation
The project includes a validation layer specifically for pyproject.toml files to ensure that settings comply with established engineering standards. This is implemented in the FlextValidatorSettings class.
Validation Rules
The scanner checks for specific configurations that might compromise code quality or type safety:
- Mypy Settings: Detects
ignore_errors = trueglobally or in module overrides (RuleCONFIG-001), and checks for disabled definitions (CONFIG-003,CONFIG-004). - Pyright Settings: Ensures
reportPrivateUsageis not set tofalse(RuleCONFIG-005).
This flow illustrates how configuration files are statically analyzed for compliance.
Sources: src/flext_tests/_validator/_settings_parts/settings_part_01.py:61-125, src/flext_tests/_validator/_settings_parts/settings_part_02.py:15-38
Violation Schema
Violations are structured data models that pinpoint exactly where a setting fails compliance.
| Field | Description |
|---|---|
file_path | The path to the pyproject.toml being scanned. |
line_number | The specific line where the offending setting was found. |
rule_id | The unique identifier for the validation rule (e.g., CONFIG-001). |
severity | The impact level of the violation. |
code_snippet | The actual text from the file causing the violation. |
Sources: src/flext_tests/_validator/_settings_parts/settings_part_01.py:46-59
Project-Level Configuration (pyproject.toml)
The pyproject.toml file serves as the source of truth for project metadata and tool-specific settings. It is categorized into [MANAGED] sections (enforced by infrastructure) and [CUSTOM] sections.
Tool Configuration Summary
- [tool.flext.docs]: Defines the project class as
test. - [tool.mypy]: Configures strict type checking, plugins (pydantic, returns), and python version 3.13.
- [tool.pyright]: Sets strict type checking mode and platform-specific execution environments.
- [tool.coverage.report]: Sets a failure threshold (
fail_under = 25).
Sources: pyproject.toml:161-162, pyproject.toml:169-191, pyproject.toml:343-345
Runtime Alias Binding
To facilitate a concise testing API, the system binds several canonical FLEXT runtime aliases to test class instances during setup.
The diagram represents the aliases injected into test instances for easier access to framework utilities.
Sources: src/flext_tests/_fixtures/settings.py:44-65
Conclusion
The Environment Settings system in flext-tests provides a robust framework for managing test configurations through automated singleton resets, typed settings instances, and strict static validation of configuration files. By centralizing these mechanisms in shared fixtures and validators, the project ensures consistent behavior and high quality across the entire FLEXT ecosystem.