Skip to content
Draft
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
9 changes: 7 additions & 2 deletions src/azure-cli-core/azure/cli/core/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ def __init__(self, commands_loader_cls=None, random_config_dir=False, **kwargs):
from knack.completion import ARGCOMPLETE_ENV_NAME
from knack.util import ensure_dir

env_patch = None

if random_config_dir:
config_dir = os.path.join(GLOBAL_CONFIG_DIR, 'dummy_cli_config_dir', random_string())
# Knack prioritizes the AZURE_CONFIG_DIR env over the config_dir param, and other functions may call
# get_config_dir directly. We need to set the env to make sure the config_dir is used.
self.env_patch = patch.dict(os.environ, {'AZURE_CONFIG_DIR': config_dir})
self.env_patch.start()
env_patch = patch.dict(os.environ, {'AZURE_CONFIG_DIR': config_dir})
env_patch.start()

# Always copy command index to avoid initializing it again
files_to_copy = ['commandIndex.json']
Expand Down Expand Up @@ -61,6 +63,9 @@ def __init__(self, commands_loader_cls=None, random_config_dir=False, **kwargs):
help_cls=AzCliHelp,
invocation_cls=AzCliCommandInvoker)

if random_config_dir:
env_patch.stop()

self.data['headers'] = {} # the x-ms-client-request-id is generated before a command is to execute
self.data['command'] = 'unknown'
self.data['completer_active'] = ARGCOMPLETE_ENV_NAME in os.environ
Expand Down
1 change: 0 additions & 1 deletion src/azure-cli-testsdk/azure/cli/testsdk/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def tearDown(self):
if self.random_config_dir:
from azure.cli.core.util import rmtree_with_retry
rmtree_with_retry(self.cli_ctx.config.config_dir)
self.cli_ctx.env_patch.stop()
super(ScenarioTest, self).tearDown()

def create_random_name(self, prefix, length):
Expand Down