diff --git a/sdk/eventhub/azure-eventhub/conftest.py b/sdk/eventhub/azure-eventhub/conftest.py index b89d82af4ad6..0d405dec5c58 100644 --- a/sdk/eventhub/azure-eventhub/conftest.py +++ b/sdk/eventhub/azure-eventhub/conftest.py @@ -18,6 +18,7 @@ from uamqp import ReceiveClient from uamqp.authentication import SASTokenAuth +from devtools_testutils import get_region_override # Ignore async tests for Python < 3.5 collect_ignore = [] @@ -32,7 +33,7 @@ NAMESPACE_PREFIX = "eh-ns" EVENTHUB_PREFIX = "eh" EVENTHUB_DEFAULT_AUTH_RULE_NAME = 'RootManageSharedAccessKey' -LOCATION = "westus" +LOCATION = get_region_override("westus") def pytest_addoption(parser): diff --git a/sdk/servicebus/azure-servicebus/tests/servicebus_preparer.py b/sdk/servicebus/azure-servicebus/tests/servicebus_preparer.py index 14ae04a1b4c3..ece97067e9f0 100644 --- a/sdk/servicebus/azure-servicebus/tests/servicebus_preparer.py +++ b/sdk/servicebus/azure-servicebus/tests/servicebus_preparer.py @@ -9,7 +9,7 @@ from azure_devtools.scenario_tests.exceptions import AzureTestError from devtools_testutils import ( - ResourceGroupPreparer, AzureMgmtPreparer, FakeResource + ResourceGroupPreparer, AzureMgmtPreparer, FakeResource, get_region_override ) from devtools_testutils.resource_testcase import RESOURCE_GROUP_PARAM @@ -27,7 +27,7 @@ class ServiceBusNamespacePreparer(AzureMgmtPreparer): def __init__(self, name_prefix='', use_cache=False, - sku='Standard', location='westus', + sku='Standard', location=get_region_override('westus'), parameter_name=SERVICEBUS_NAMESPACE_PARAM, resource_group_parameter_name=RESOURCE_GROUP_PARAM, disable_recording=True, playback_fake_resource=None, diff --git a/tools/azure-sdk-tools/devtools_testutils/__init__.py b/tools/azure-sdk-tools/devtools_testutils/__init__.py index 107057a0c851..ffbd9f509d4a 100644 --- a/tools/azure-sdk-tools/devtools_testutils/__init__.py +++ b/tools/azure-sdk-tools/devtools_testutils/__init__.py @@ -1,5 +1,5 @@ from .mgmt_testcase import (AzureMgmtTestCase, AzureMgmtPreparer) -from .azure_testcase import AzureTestCase, is_live +from .azure_testcase import AzureTestCase, is_live, get_region_override from .resource_testcase import (FakeResource, ResourceGroupPreparer, RandomNameResourceGroupPreparer, CachedResourceGroupPreparer) from .storage_testcase import (FakeStorageAccount, StorageAccountPreparer) from .keyvault_preparer import KeyVaultPreparer @@ -8,7 +8,7 @@ 'AzureMgmtTestCase', 'AzureMgmtPreparer', 'FakeResource', 'ResourceGroupPreparer', 'FakeStorageAccount', 'StorageAccountPreparer', - 'AzureTestCase', 'is_live', + 'AzureTestCase', 'is_live', 'get_region_override', 'KeyVaultPreparer', 'RandomNameResourceGroupPreparer', 'CachedResourceGroupPreparer' ] diff --git a/tools/azure-sdk-tools/devtools_testutils/azure_testcase.py b/tools/azure-sdk-tools/devtools_testutils/azure_testcase.py index d3703237ffa4..f0969bf078f5 100644 --- a/tools/azure-sdk-tools/devtools_testutils/azure_testcase.py +++ b/tools/azure-sdk-tools/devtools_testutils/azure_testcase.py @@ -65,6 +65,13 @@ def is_live(): return is_live._cache +def get_region_override(default='westus'): + region = os.environ.get('RESOURCE_REGION', None) or default + if not region: + raise ValueError('Region should not be None; set a non-empty-string region to either the RESOURCE_REGION environment variable or the default parameter to this function.') + return region + + def _is_autorest_v3(client_class): """ IS this client a autorestv3/track2 one?. Could be refined later if necessary. diff --git a/tools/azure-sdk-tools/devtools_testutils/resource_testcase.py b/tools/azure-sdk-tools/devtools_testutils/resource_testcase.py index daee710d6b73..c3cabf584083 100644 --- a/tools/azure-sdk-tools/devtools_testutils/resource_testcase.py +++ b/tools/azure-sdk-tools/devtools_testutils/resource_testcase.py @@ -60,7 +60,7 @@ def create_resource(self, name, **kwargs): parameters = {'location': self.location} if self.delete_after_tag_timedelta: expiry = datetime.datetime.utcnow() + self.delete_after_tag_timedelta - parameters['tags'] = {'DeleteAfter': expiry.isoformat()} + parameters['tags'] = {'DeleteAfter': expiry.replace(microsecond=0).isoformat()} try: self.resource = self.client.resource_groups.create_or_update( name, parameters