Skip to content

Commit 44947bd

Browse files
Sign CLA
Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
1 parent 5f80c75 commit 44947bd

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

tests/integration/test_config_validation_flow.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from datetime import timedelta
1818
from pathlib import Path
1919
from typing import TYPE_CHECKING
20-
from unittest.mock import AsyncMock, Mock, NonCallableMock
20+
from unittest.mock import AsyncMock, Mock
2121

2222
import pytest
2323

@@ -33,24 +33,14 @@
3333

3434
@pytest.fixture(autouse=True)
3535
def setup_test_container(test_settings):
36-
"""Override DI-injected settings for services resolved through the container.
37-
38-
Uses ``container.use_overrides`` so that pre-existing overrides are
39-
snapshot-restored automatically on teardown without touching private state.
40-
41-
Note: ``codeweaver.core.get_settings()`` constructs settings directly from
42-
the installed package configuration and does *not* consult this container,
43-
so this override only affects services that receive their settings via DI
44-
resolution. Code paths that call ``get_settings()`` directly (e.g.
45-
``CheckpointManager._extract_fingerprint``) must be patched separately.
46-
"""
47-
from codeweaver.core.config.settings_type import CodeWeaverSettingsType
36+
"""Create test DI container and override settings so real `get_settings()` works."""
4837
from codeweaver.core.di.container import get_container
49-
38+
from codeweaver.core.config.settings_type import CodeWeaverSettingsType
5039

5140
container = get_container()
52-
with container.use_overrides({CodeWeaverSettingsType: test_settings}):
53-
yield container
41+
container.override(CodeWeaverSettingsType, test_settings)
42+
yield container
43+
container.clear()
5444

5545

5646
@pytest.fixture
@@ -114,11 +104,12 @@ def mock_checkpoint_manager(test_checkpoint_data: dict) -> AsyncMock:
114104
checkpoint.collection_metadata = metadata
115105

116106
manager.load = AsyncMock(return_value=checkpoint)
117-
# Some tests may call `load_checkpoint()` instead of `load()`;
118-
# make it an alias so both return the same checkpoint object.
119-
manager.load_checkpoint = manager.load
120107
manager.validate_checkpoint_compatibility = AsyncMock(return_value=(True, "NONE"))
121108

109+
# Do not mock _extract_fingerprint or _create_fingerprint
110+
# The real implementation will be run, but it requires the global settings to exist,
111+
# which we've solved by using `container.override(CodeWeaverSettingsType, test_settings)`
112+
# However, CheckpointManager uses `get_settings()` from core_settings, which reads from dependency container.
122113

123114
return manager
124115

@@ -158,13 +149,9 @@ def mock_vector_store() -> AsyncMock:
158149

159150

160151
@pytest.fixture
161-
def test_settings() -> NonCallableMock:
162-
"""Create test Settings with default configuration.
163-
164-
Uses ``NonCallableMock`` so the DI container does not invoke the object as
165-
a factory when resolving ``CodeWeaverSettingsType``.
166-
"""
167-
settings = NonCallableMock()
152+
def test_settings() -> Mock:
153+
"""Create test Settings with default configuration."""
154+
settings = Mock()
168155

169156
# Provider settings
170157
settings.provider = Mock()

0 commit comments

Comments
 (0)