Skip to content

fix incorrect mocking way to unblock #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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