Fixtures
provide.testkit.hub.fixtures
¶
Hub Testing Fixtures for Foundation.
Provides pytest fixtures for testing hub and component functionality, including container directories and component registration scenarios.
Dependency Injection Testing¶
These fixtures support Foundation's dependency injection architecture, enabling isolated testing without global state resets.
Key fixtures:
- isolated_container: Creates a fresh Container for each test
- isolated_hub: Creates a Hub with an isolated Container
- default_container_directory: Provides temp directory for containers
Example usage
def test_with_isolated_hub(isolated_hub): ... # Each test gets its own Hub with clean state ... # No need to call reset_foundation_setup_for_testing() ... client = UniversalClient(hub=isolated_hub) ... # Test proceeds with isolated dependencies
Functions¶
default_container_directory
¶
Provides a default directory for container operations in tests.
This fixture is used by tests that need a temporary directory for container-related operations.
Source code in provide/testkit/hub/fixtures.py
isolated_container
¶
Create an isolated Container for dependency injection testing.
This fixture provides a fresh Container instance for each test, eliminating the need for global state resets between tests.
Returns:
| Name | Type | Description |
|---|---|---|
Container |
Any
|
A new Container instance with no pre-registered dependencies. |
Example
def test_my_component(isolated_container): ... # Register test-specific dependencies ... isolated_container.register("my_service", MyService()) ... # Test with isolated state ... service = isolated_container.resolve("my_service") ... assert service is not None
Note
Tests using this fixture do not need to call reset_foundation_setup_for_testing() as each test gets a fresh container automatically.
Source code in provide/testkit/hub/fixtures.py
isolated_hub
¶
Create an isolated Hub with fresh registries for testing.
This fixture provides a Hub instance with isolated registries, enabling dependency injection testing without global state side effects.
Returns:
| Name | Type | Description |
|---|---|---|
Hub |
Any
|
A Hub instance with isolated registries. |
Example
def test_with_di(isolated_hub): ... # Hub has fresh, isolated state ... client = UniversalClient(hub=isolated_hub) ... # Test proceeds without affecting global Hub ... response = await client.get("https://api.example.com") ... assert response.status == 200
Note
This fixture is ideal for unit tests that need Hub functionality but want complete isolation from other tests. No reset functions are needed when using this fixture.