|
17 | 17 | from datetime import timedelta |
18 | 18 | from pathlib import Path |
19 | 19 | from typing import TYPE_CHECKING |
20 | | -from unittest.mock import AsyncMock, Mock, NonCallableMock |
| 20 | +from unittest.mock import AsyncMock, Mock |
21 | 21 |
|
22 | 22 | import pytest |
23 | 23 |
|
|
33 | 33 |
|
34 | 34 | @pytest.fixture(autouse=True) |
35 | 35 | 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.""" |
48 | 37 | from codeweaver.core.di.container import get_container |
49 | | - |
| 38 | + from codeweaver.core.config.settings_type import CodeWeaverSettingsType |
50 | 39 |
|
51 | 40 | 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() |
54 | 44 |
|
55 | 45 |
|
56 | 46 | @pytest.fixture |
@@ -114,11 +104,12 @@ def mock_checkpoint_manager(test_checkpoint_data: dict) -> AsyncMock: |
114 | 104 | checkpoint.collection_metadata = metadata |
115 | 105 |
|
116 | 106 | 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 |
120 | 107 | manager.validate_checkpoint_compatibility = AsyncMock(return_value=(True, "NONE")) |
121 | 108 |
|
| 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. |
122 | 113 |
|
123 | 114 | return manager |
124 | 115 |
|
@@ -158,13 +149,9 @@ def mock_vector_store() -> AsyncMock: |
158 | 149 |
|
159 | 150 |
|
160 | 151 | @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() |
168 | 155 |
|
169 | 156 | # Provider settings |
170 | 157 | settings.provider = Mock() |
|
0 commit comments