Internal
๐ค AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
provide.foundation.testmode.internal
¶
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 a test-safe state.
This resets structlog but configures it with a wrapper class that supports the trace method. Using reset_defaults() alone would result in BoundLoggerFilteringAtNotset which lacks trace().
Source code in provide/foundation/testmode/internal.py
reset_test_mode_cache
¶
Pin test mode cache to True; preserve click-testing cache.
During a test run, test mode is always True. Previous behavior cleared both caches (setting them to None), which forced expensive sys._getframe() walks (or worse, inspect.stack() + getmodule()) on every subsequent Foundation re-initialization โ ~17 GB of allocations across 10K resets.
Now we pin _test_mode_cache = True so the fast-path cache hit
fires immediately, and leave _click_testing_cache untouched
because Click-testing status also doesn't change mid-run.
Tests that specifically need to exercise detection logic can call
_clear_test_mode_cache() directly from detection.py.
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.