Skip to content
Closed
Show file tree
Hide file tree
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: 6 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ jobs:
python.version: '3.6'
tox_env: 'py36'
Python38:
python.version: '3.8'
python.version: '3.8.2'
tox_env: 'py38'
steps:
- task: UsePythonVersion@0
Expand All @@ -396,7 +396,7 @@ jobs:
Python36:
python.version: '3.6'
Python38:
python.version: '3.8'
python.version: '3.8.2'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python $(python.version)'
Expand All @@ -417,7 +417,7 @@ jobs:
Python36:
python.version: '3.6'
Python38:
python.version: '3.8'
python.version: '3.8.2'
steps:
- template: .azure-pipelines/templates/automation_test.yml
parameters:
Expand All @@ -434,7 +434,7 @@ jobs:
Python36:
python.version: '3.6'
Python38:
python.version: '3.8'
python.version: '3.8.2'
steps:
- template: .azure-pipelines/templates/automation_test.yml
parameters:
Expand All @@ -451,7 +451,7 @@ jobs:
Python36:
python.version: '3.6'
Python38:
python.version: '3.8'
python.version: '3.8.2'
steps:
- template: .azure-pipelines/templates/automation_test.yml
parameters:
Expand All @@ -468,7 +468,7 @@ jobs:
Python36:
python.version: '3.6'
Python38:
python.version: '3.8'
python.version: '3.8.2'
steps:
- template: .azure-pipelines/templates/automation_test.yml
parameters:
Expand Down
17 changes: 16 additions & 1 deletion src/azure-cli-testsdk/azure/cli/testsdk/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# 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

Expand Down Expand Up @@ -95,3 +95,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)