From 9b59e4e402154c45f52090c102efb08be9adf603 Mon Sep 17 00:00:00 2001 From: Jianhui Harold Date: Fri, 9 Oct 2020 18:09:02 +0800 Subject: [PATCH] fix incorrect mocking way to unblock (#262) * fix * fix style --- azdev/operations/tests/test_benchmark.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/azdev/operations/tests/test_benchmark.py b/azdev/operations/tests/test_benchmark.py index efd69d87..f7c307b7 100644 --- a/azdev/operations/tests/test_benchmark.py +++ b/azdev/operations/tests/test_benchmark.py @@ -81,14 +81,18 @@ def test_load_all_commands_ok(self): def test_load_all_commands_fail(self): import sys - sys.modules["azure.cli.core"] = mock.MagicMock(side_effect=ImportError) + original_azure_cli_core_mod = sys.modules.get("azure.cli.core") + sys.modules["azure.cli.core"] = None with self.assertRaisesRegex(CLIError, "Azure CLI is not installed"): _benchmark_load_all_commands() - del sys.modules[ - "azure.cli.core" - ] # restore azure.cli.core to be unimported as the original + if original_azure_cli_core_mod: + sys.modules["azure.cli.core"] = original_azure_cli_core_mod + else: + del sys.modules[ + "azure.cli.core" + ] # restore azure.cli.core to the unimported status # class _MockedMapResultCounter: