def setup_workspace(workspace_name, subscription_id, resource_group, cli_auth, location): """ This sets up an Azure Workspace. An existing Azure Workspace is used or a new one is created if needed for the pytest run. Args: workspace_name (str): Centralized location on Azure to work with all the artifacts used by AzureML service subscription_id (str): the Azure subscription id resource_group (str): Azure Resource Groups are logical collections of assets associated with a project. Resource groups make it easy to track or delete all resources associated with a project by tracking or deleting the Resource group. cli_auth Azure authentication location (str): workspace reference Returns: ws: workspace reference """ logger.debug('setup: workspace_name is {}'.format(workspace_name)) logger.debug('setup: resource_group is {}'.format(resource_group)) logger.debug('setup: subid is {}'.format(subscription_id)) logger.debug('setup: location is {}'.format(location)) try: # use existing workspace if there is one ws = Workspace.get( name=workspace_name, subscription_id=subscription_id, resource_group=resource_group, auth=cli_auth ) except WorkspaceException: # this call might take a minute or two. logger.debug('Creating new workspace') ws = Workspace.create( name=workspace_name, subscription_id=subscription_id, resource_group=resource_group, # create_resource_group=True, location=location, auth=cli_auth ) return ws