From 84134911f00950fdb4e0dd1377c2e80b49a5d3f2 Mon Sep 17 00:00:00 2001 From: Harold Zeng Date: Thu, 23 Jul 2020 12:46:30 +0800 Subject: [PATCH 1/5] resert #13680 --- .../azure/cli/testsdk/base.py | 4 +-- .../azure/cli/testsdk/patches.py | 28 +++---------------- .../dla/tests/latest/recording_processors.py | 3 +- 3 files changed, 7 insertions(+), 28 deletions(-) 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/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' From 536264376bc659f6e641266596cf5d1032cb95f4 Mon Sep 17 00:00:00 2001 From: Harold Zeng Date: Thu, 23 Jul 2020 14:25:31 +0800 Subject: [PATCH 2/5] test on azure-python-devtools --- .azure-pipelines/templates/automation_test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.azure-pipelines/templates/automation_test.yml b/.azure-pipelines/templates/automation_test.yml index 76b8891b35c..f69b4d34525 100644 --- a/.azure-pipelines/templates/automation_test.yml +++ b/.azure-pipelines/templates/automation_test.yml @@ -13,6 +13,8 @@ steps: source env/bin/activate + pip install git+https://github.com/haroldrandom/azure-python-devtools.git@fix-python-3.8.3 + if [[ "$(System.PullRequest.TargetBranch)" != "" ]]; then azdev test --series --repo=./ --src=HEAD --tgt=origin/$(System.PullRequest.TargetBranch) --cli-ci --profile ${{ parameters.profile }} else From 03a7613477934c67c21365aae05fe57d5326d11b Mon Sep 17 00:00:00 2001 From: Harold Zeng Date: Thu, 23 Jul 2020 15:01:15 +0800 Subject: [PATCH 3/5] fix full test pipeline --- scripts/ci/test_automation.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/ci/test_automation.sh b/scripts/ci/test_automation.sh index 080b3e118fc..c979637857d 100755 --- a/scripts/ci/test_automation.sh +++ b/scripts/ci/test_automation.sh @@ -54,4 +54,7 @@ az -v az -h title 'Running tests' + +pip install git+https://github.com/haroldrandom/azure-python-devtools.git@fix-python-3.8.3 + python -m automation test --ci --profile $target_profile From e9e2ce5f5d10be5c1276b5450a642025df63cfd8 Mon Sep 17 00:00:00 2001 From: Harold Zeng Date: Wed, 29 Jul 2020 11:26:07 +0800 Subject: [PATCH 4/5] revert beta version of azure-devtools --- .azure-pipelines/templates/automation_test.yml | 2 -- scripts/ci/test_automation.sh | 3 --- 2 files changed, 5 deletions(-) diff --git a/.azure-pipelines/templates/automation_test.yml b/.azure-pipelines/templates/automation_test.yml index f69b4d34525..76b8891b35c 100644 --- a/.azure-pipelines/templates/automation_test.yml +++ b/.azure-pipelines/templates/automation_test.yml @@ -13,8 +13,6 @@ steps: source env/bin/activate - pip install git+https://github.com/haroldrandom/azure-python-devtools.git@fix-python-3.8.3 - if [[ "$(System.PullRequest.TargetBranch)" != "" ]]; then azdev test --series --repo=./ --src=HEAD --tgt=origin/$(System.PullRequest.TargetBranch) --cli-ci --profile ${{ parameters.profile }} else diff --git a/scripts/ci/test_automation.sh b/scripts/ci/test_automation.sh index c979637857d..080b3e118fc 100755 --- a/scripts/ci/test_automation.sh +++ b/scripts/ci/test_automation.sh @@ -54,7 +54,4 @@ az -v az -h title 'Running tests' - -pip install git+https://github.com/haroldrandom/azure-python-devtools.git@fix-python-3.8.3 - python -m automation test --ci --profile $target_profile From b6973de4996bae3b8a49db61dbc4975f5ae72f83 Mon Sep 17 00:00:00 2001 From: Harold Zeng Date: Wed, 29 Jul 2020 11:37:54 +0800 Subject: [PATCH 5/5] azure-devtools==1.2.0 --- src/azure-cli-testsdk/setup.py | 2 +- src/azure-cli/requirements.py3.Darwin.txt | 2 +- src/azure-cli/requirements.py3.Linux.txt | 2 +- src/azure-cli/requirements.py3.windows.txt | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) 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/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