Skip to content

Commit 06743cb

Browse files
author
chenxi
committed
fix test dependency
1 parent 97abed3 commit 06743cb

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/aks-agent/azext_aks_agent/tests/latest/test_aks_agent.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616
from azure.cli.core.util import CLIError
1717

1818
# Mock the holmes modules before any imports that might trigger holmes imports
19-
holmes_mock = Mock()
20-
holmes_mock.config = Mock()
21-
holmes_mock.config.Config = Mock()
22-
sys.modules['holmes'] = holmes_mock
23-
sys.modules['holmes.config'] = holmes_mock.config
19+
sys.modules['holmes'] = Mock()
20+
sys.modules['holmes.config'] = Mock()
2421
sys.modules['holmes.core'] = Mock()
2522
sys.modules['holmes.core.prompt'] = Mock()
2623
sys.modules['holmes.interactive'] = Mock()

src/aks-agent/azext_aks_agent/tests/latest/test_aks_agent_init.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6-
import sys
76
import types
87
import unittest
98
from unittest.mock import patch, MagicMock
@@ -22,7 +21,7 @@
2221
ERROR_COLOR=MagicMock(),
2322
HELP_COLOR=MagicMock(),
2423
),
25-
console=mock_console_mod, # 添加 console 子模块
24+
console=mock_console_mod,
2625
)
2726
)
2827

@@ -32,21 +31,26 @@
3231
)
3332
)
3433

35-
# 注册所有可能被 import 的路径
36-
sys.modules.update({
37-
'holmes': mock_holmes,
38-
'holmes.interactive': mock_holmes.interactive,
39-
'holmes.utils': mock_holmes.utils,
40-
'holmes.utils.colors': mock_holmes.utils.colors,
41-
'holmes.utils.console': mock_holmes.utils.console,
42-
'holmes.utils.console.logging': mock_holmes.utils.console.logging,
43-
'rich': mock_rich,
44-
'rich.console': mock_rich.console,
45-
})
46-
4734

4835
class TestAksAgentInit(unittest.TestCase):
4936

37+
def setUp(self):
38+
patcher = patch.dict(
39+
'sys.modules',
40+
{
41+
'holmes': mock_holmes,
42+
'holmes.interactive': mock_holmes.interactive,
43+
'holmes.utils': mock_holmes.utils,
44+
'holmes.utils.colors': mock_holmes.utils.colors,
45+
'holmes.utils.console': mock_holmes.utils.console,
46+
'holmes.utils.console.logging': mock_holmes.utils.console.logging,
47+
'rich': mock_rich,
48+
'rich.console': mock_rich.console,
49+
}
50+
)
51+
self.addCleanup(patcher.stop)
52+
patcher.start()
53+
5054
@patch('holmes.interactive.SlashCommands')
5155
@patch('holmes.utils.colors.ERROR_COLOR')
5256
@patch('holmes.utils.colors.HELP_COLOR')

0 commit comments

Comments
 (0)