Skip to content

Commit

Permalink
fix incorrect mocking way to unblock (#262)
Browse files Browse the repository at this point in the history
* fix

* fix style
  • Loading branch information
Jianhui Harold authored Oct 9, 2020
1 parent 75a1a79 commit 9b59e4e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions azdev/operations/tests/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9b59e4e

Please sign in to comment.