diff --git a/src/azure-cli-testsdk/azure/cli/testsdk/base.py b/src/azure-cli-testsdk/azure/cli/testsdk/base.py index 62685d62613..0d15b1cc39e 100644 --- a/src/azure-cli-testsdk/azure/cli/testsdk/base.py +++ b/src/azure-cli-testsdk/azure/cli/testsdk/base.py @@ -14,13 +14,13 @@ from azure_devtools.scenario_tests import (IntegrationTestBase, ReplayableTest, SubscriptionRecordingProcessor, OAuthRequestResponsesFilter, LargeRequestBodyProcessor, LargeResponseBodyProcessor, LargeResponseBodyReplacer, RequestUrlNormalizer, - live_only, DeploymentNameReplacer, patch_time_sleep_api, create_random_name) + live_only, DeploymentNameReplacer, create_random_name) from azure_devtools.scenario_tests.const import MOCKED_SUBSCRIPTION_ID, ENV_SKIP_ASSERT from .patches import (patch_load_cached_subscriptions, patch_main_exception_handler, patch_retrieve_token_for_user, patch_long_run_operation_delay, - patch_progress_controller, patch_get_current_system_username) + patch_progress_controller, patch_get_current_system_username, patch_time_sleep_api) from .exceptions import CliExecutionError from .utilities import find_recording_dir, StorageAccountKeyReplacer, GraphClientPasswordReplacer, GeneralNameReplacer from .reverse_dependency import get_dummy_cli diff --git a/src/azure-cli-testsdk/azure/cli/testsdk/patches.py b/src/azure-cli-testsdk/azure/cli/testsdk/patches.py index bb7dd880a41..8a86858937f 100644 --- a/src/azure-cli-testsdk/azure/cli/testsdk/patches.py +++ b/src/azure-cli-testsdk/azure/cli/testsdk/patches.py @@ -3,14 +3,21 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from azure_devtools.scenario_tests import mock_in_unit_test from azure_devtools.scenario_tests.const import MOCKED_SUBSCRIPTION_ID, MOCKED_TENANT_ID +from azure_devtools.scenario_tests.exceptions import AzureTestError from .exceptions import CliExecutionError MOCKED_USER_NAME = 'example@example.com' +def patch_time_sleep_api(unit_test): + def _time_sleep_skip(*_): + return + + mock_in_unit_test(unit_test, 'time.sleep', _time_sleep_skip) + + def patch_progress_controller(unit_test): def _mock_pass(*args, **kwargs): # pylint: disable=unused-argument pass @@ -95,3 +102,18 @@ def _get_current_system_username(*args, **kwargs): # pylint: disable=unused-arg return create_random_name(prefix='example_') mock_in_unit_test(unit_test, 'azure.cli.core.local_context._get_current_system_username', _get_current_system_username) + + +def mock_in_unit_test(unit_test, target, replacement): + try: + import unittest.mock as mock + except ImportError: + import mock + import unittest + + if not isinstance(unit_test, unittest.TestCase): + raise AzureTestError('Patches can be only called from a unit test') + + mp = mock.patch(target, replacement) + mp.__enter__() + unit_test.addCleanup(mp.__exit__, None, None, None) diff --git a/src/azure-cli/azure/cli/command_modules/dla/tests/latest/recording_processors.py b/src/azure-cli/azure/cli/command_modules/dla/tests/latest/recording_processors.py index 5c598a9fea1..955c6bedadf 100644 --- a/src/azure-cli/azure/cli/command_modules/dla/tests/latest/recording_processors.py +++ b/src/azure-cli/azure/cli/command_modules/dla/tests/latest/recording_processors.py @@ -3,7 +3,8 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from azure_devtools.scenario_tests import RecordingProcessor, mock_in_unit_test +from azure_devtools.scenario_tests import RecordingProcessor +from azure.cli.testsdk.patches import mock_in_unit_test MOCK_JOB_ID = '00000000-0000-0000-0000-000000000000' diff --git a/src/azure-cli/azure/cli/command_modules/dls/tests/latest/test_dls_commands.py b/src/azure-cli/azure/cli/command_modules/dls/tests/latest/test_dls_commands.py index 89a24a4e9d0..9abbf6a9a06 100644 --- a/src/azure-cli/azure/cli/command_modules/dls/tests/latest/test_dls_commands.py +++ b/src/azure-cli/azure/cli/command_modules/dls/tests/latest/test_dls_commands.py @@ -138,7 +138,7 @@ def tearDown(self): local_folder = self.kwargs.get('local_folder', None) if local_folder and os.path.exists(local_folder): rmtree(local_folder) - self.mp.__exit__() + self.mp.__exit__(None, None, None) return super(DataLakeStoreFileScenarioTest, self).tearDown() @ResourceGroupPreparer(name_prefix='cls_test_adls_file') diff --git a/src/azure-cli/setup.py b/src/azure-cli/setup.py index d913286f613..8a6786a7a2b 100644 --- a/src/azure-cli/setup.py +++ b/src/azure-cli/setup.py @@ -74,7 +74,7 @@ 'azure-mgmt-compute~=12.0', 'azure-mgmt-consumption~=2.0', 'azure-mgmt-containerinstance~=1.4', - 'azure-mgmt-containerregistry~=3.0.0rc12', + 'azure-mgmt-containerregistry==3.0.0rc12', 'azure-mgmt-containerservice~=9.0.1', 'azure-mgmt-cosmosdb~=0.14.0', 'azure-mgmt-datalake-analytics~=0.2.1',