diff --git a/src/azure-cli-testsdk/azure/cli/testsdk/base.py b/src/azure-cli-testsdk/azure/cli/testsdk/base.py index 0d15b1cc39e..62685d62613 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, create_random_name) + live_only, DeploymentNameReplacer, patch_time_sleep_api, 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_time_sleep_api) + patch_progress_controller, patch_get_current_system_username) 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 8a86858937f..d59833dfa16 100644 --- a/src/azure-cli-testsdk/azure/cli/testsdk/patches.py +++ b/src/azure-cli-testsdk/azure/cli/testsdk/patches.py @@ -3,21 +3,14 @@ # 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 @@ -101,19 +94,6 @@ def _get_current_system_username(*args, **kwargs): # pylint: disable=unused-arg from .utilities import create_random_name 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) + mock_in_unit_test(unit_test, + 'azure.cli.core.local_context._get_current_system_username', + _get_current_system_username) diff --git a/src/azure-cli-testsdk/setup.py b/src/azure-cli-testsdk/setup.py index 080f6a2abe5..deefdf2bc7b 100644 --- a/src/azure-cli-testsdk/setup.py +++ b/src/azure-cli-testsdk/setup.py @@ -31,7 +31,7 @@ 'jmespath', 'mock', 'vcrpy>=1.10.3', - 'azure-devtools~=1.0.0' + 'azure-devtools==1.2.0' ] with open('README.rst', 'r', encoding='utf-8') as f: 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 955c6bedadf..5c598a9fea1 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,8 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from azure_devtools.scenario_tests import RecordingProcessor -from azure.cli.testsdk.patches import mock_in_unit_test +from azure_devtools.scenario_tests import RecordingProcessor, mock_in_unit_test MOCK_JOB_ID = '00000000-0000-0000-0000-000000000000' diff --git a/src/azure-cli/requirements.py3.Darwin.txt b/src/azure-cli/requirements.py3.Darwin.txt index 2c9bd54abd8..088759ada39 100644 --- a/src/azure-cli/requirements.py3.Darwin.txt +++ b/src/azure-cli/requirements.py3.Darwin.txt @@ -12,7 +12,7 @@ azure-cli-telemetry==1.0.4 azure-common==1.1.22 azure-cosmos==3.1.0 azure-datalake-store==0.0.48 -azure-devtools==1.0.0 +azure-devtools==1.2.0 azure-functions-devops-build==0.0.22 azure-graphrbac==0.60.0 azure-keyvault==1.1.0 diff --git a/src/azure-cli/requirements.py3.Linux.txt b/src/azure-cli/requirements.py3.Linux.txt index 439d20b22ae..64b0992a752 100644 --- a/src/azure-cli/requirements.py3.Linux.txt +++ b/src/azure-cli/requirements.py3.Linux.txt @@ -12,7 +12,7 @@ azure-cli-telemetry==1.0.4 azure-common==1.1.22 azure-cosmos==3.1.0 azure-datalake-store==0.0.48 -azure-devtools==1.0.0 +azure-devtools==1.2.0 azure-functions-devops-build==0.0.22 azure-graphrbac==0.60.0 azure-keyvault==1.1.0 diff --git a/src/azure-cli/requirements.py3.windows.txt b/src/azure-cli/requirements.py3.windows.txt index 7a5cc701371..663da1d1473 100644 --- a/src/azure-cli/requirements.py3.windows.txt +++ b/src/azure-cli/requirements.py3.windows.txt @@ -12,6 +12,7 @@ azure-cli-telemetry==1.0.4 azure-common==1.1.22 azure-cosmos==3.1.0 azure-datalake-store==0.0.48 +azure-devtools==1.2.0 azure-functions-devops-build==0.0.22 azure-graphrbac==0.60.0 azure-keyvault==1.1.0