Skip to content

Commit 9b59e4e

Browse files
author
Jianhui Harold
authored
fix incorrect mocking way to unblock (#262)
* fix * fix style
1 parent 75a1a79 commit 9b59e4e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

azdev/operations/tests/test_benchmark.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,18 @@ def test_load_all_commands_ok(self):
8181
def test_load_all_commands_fail(self):
8282
import sys
8383

84-
sys.modules["azure.cli.core"] = mock.MagicMock(side_effect=ImportError)
84+
original_azure_cli_core_mod = sys.modules.get("azure.cli.core")
85+
sys.modules["azure.cli.core"] = None
8586

8687
with self.assertRaisesRegex(CLIError, "Azure CLI is not installed"):
8788
_benchmark_load_all_commands()
8889

89-
del sys.modules[
90-
"azure.cli.core"
91-
] # restore azure.cli.core to be unimported as the original
90+
if original_azure_cli_core_mod:
91+
sys.modules["azure.cli.core"] = original_azure_cli_core_mod
92+
else:
93+
del sys.modules[
94+
"azure.cli.core"
95+
] # restore azure.cli.core to the unimported status
9296

9397

9498
# class _MockedMapResultCounter:

0 commit comments

Comments
 (0)