Internal
provide.foundation.testmode.internal
¶
TODO: Add module docstring.
Functions¶
reset_circuit_breaker_state
¶
Reset all circuit breaker instances to ensure test isolation.
This function resets all circuit breaker instances that were created by the @circuit_breaker decorator and direct instantiation to ensure their state doesn't leak between tests.
Source code in provide/foundation/testmode/internal.py
reset_configuration_state
¶
Reset configuration state to defaults.
This resets all versioned configurations and their managers to ensure clean state between tests.
Source code in provide/foundation/testmode/internal.py
reset_coordinator_state
¶
Reset setup coordinator state.
This clears cached coordinator state including setup logger cache and other coordinator-managed state.
Source code in provide/foundation/testmode/internal.py
reset_event_loops
¶
Close any running event loops to prevent worker shutdown hangs.
This is critical for pytest-xdist workers to shut down cleanly after async tests complete.
IMPORTANT: This MUST be called AFTER reset_time_machine_state() to ensure time patches are stopped before creating a new event loop. Otherwise the new loop may cache frozen time.monotonic references.
Source code in provide/foundation/testmode/internal.py
reset_eventsets_state
¶
Reset event set registry and discovery state.
This clears the event set registry to ensure clean state between tests.
Source code in provide/foundation/testmode/internal.py
reset_global_coordinator
¶
Reset the global initialization coordinator state for testing.
This function resets the singleton InitializationCoordinator state to ensure proper test isolation between test runs.
WARNING: This should only be called from test code or test fixtures. Production code should not reset the global coordinator state.
Source code in provide/foundation/testmode/internal.py
reset_hub_state
¶
Reset Hub state to defaults.
This clears the Hub registry and resets all Hub components to their initial state.
Source code in provide/foundation/testmode/internal.py
reset_logger_state
¶
Reset Foundation logger state to defaults.
This resets the lazy setup state and logger configuration flags without importing the full logger module to avoid circular dependencies.
Source code in provide/foundation/testmode/internal.py
reset_profiling_state
¶
Reset profiling state to defaults.
This clears profiling metrics and resets profiling components to ensure clean state between tests.
Source code in provide/foundation/testmode/internal.py
reset_state_managers
¶
Reset all state managers to default state.
This resets logger state managers and other state management components to ensure clean test isolation.
Source code in provide/foundation/testmode/internal.py
reset_streams_state
¶
Reset stream state to defaults.
This resets file streams and other stream-related state managed by the streams module.
Source code in provide/foundation/testmode/internal.py
reset_structlog_state
¶
Reset structlog configuration to defaults.
This is the most fundamental reset - it clears all structlog configuration and returns it to an unconfigured state.
Source code in provide/foundation/testmode/internal.py
reset_test_mode_cache
¶
Reset test mode detection cache.
This clears the cached test mode detection result, allowing fresh detection on the next call. This is important for test isolation when tests manipulate environment variables or sys.modules.
Source code in provide/foundation/testmode/internal.py
reset_time_machine_state
¶
Reset time_machine state to ensure time is not frozen.
NOTE: The actual cleanup is now handled by the _force_time_machine_cleanup fixture in tests/conftest.py, which runs BEFORE Foundation teardown.
This ensures time patches are stopped before pytest-asyncio creates event loops for the next test. This function remains as a no-op safety fallback.
Source code in provide/foundation/testmode/internal.py
reset_transport_registration_flags
¶
Reset transport auto-registration flags.
This resets the module-level flags that prevent duplicate transport registration, allowing transports to be re-registered after the registry is cleared during test cleanup.
Source code in provide/foundation/testmode/internal.py
reset_version_cache
¶
Reset version cache to defaults.
This clears the cached version to ensure clean state between tests, allowing each test to verify different version resolution scenarios.