Skip to content

Commit 513d591

Browse files
committed
Set env
1 parent 7e92221 commit 513d591

File tree

1 file changed

+13
-15
lines changed
  • src/azure-cli-core/azure/cli/core

1 file changed

+13
-15
lines changed

src/azure-cli-core/azure/cli/core/mock.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class DummyCli(AzCli):
1010
"""A dummy CLI instance can be used to facilitate automation"""
1111
def __init__(self, commands_loader_cls=None, random_config_dir=False, **kwargs):
1212
import os
13-
from unittest.mock import patch
1413

1514
from azure.cli.core import MainCommandsLoader
1615
from azure.cli.core.commands import AzCliCommandInvoker
@@ -27,6 +26,9 @@ def __init__(self, commands_loader_cls=None, random_config_dir=False, **kwargs):
2726

2827
if random_config_dir:
2928
config_dir = os.path.join(GLOBAL_CONFIG_DIR, 'dummy_cli_config_dir', random_string())
29+
# Knack prioritizes the AZURE_CONFIG_DIR env over the config_dir param, and other function may call
30+
# get_config_dir directly. We need to set the env to make sure the config_dir is used.
31+
os.environ['AZURE_CONFIG_DIR'] = config_dir
3032

3133
# In recording mode, copy login credentials from global config dir to the dummy config dir
3234
if os.getenv(ENV_VAR_TEST_LIVE, '').lower() == 'true':
@@ -42,20 +44,16 @@ def __init__(self, commands_loader_cls=None, random_config_dir=False, **kwargs):
4244
else:
4345
config_dir = GLOBAL_CONFIG_DIR
4446

45-
# Knack prioritizes the AZURE_CONFIG_DIR env over the config_dir param, we need to set the env var temporarily
46-
# to make sure it uses the config_dir param
47-
patch_env = {'AZURE_CONFIG_DIR': config_dir} if random_config_dir else {}
48-
with patch.dict('os.environ', patch_env):
49-
super(DummyCli, self).__init__(
50-
cli_name='az',
51-
config_dir=config_dir,
52-
config_env_var_prefix=ENV_VAR_PREFIX,
53-
commands_loader_cls=commands_loader_cls or MainCommandsLoader,
54-
parser_cls=AzCliCommandParser,
55-
logging_cls=AzCliLogging,
56-
output_cls=AzOutputProducer,
57-
help_cls=AzCliHelp,
58-
invocation_cls=AzCliCommandInvoker)
47+
super(DummyCli, self).__init__(
48+
cli_name='az',
49+
config_dir=config_dir,
50+
config_env_var_prefix=ENV_VAR_PREFIX,
51+
commands_loader_cls=commands_loader_cls or MainCommandsLoader,
52+
parser_cls=AzCliCommandParser,
53+
logging_cls=AzCliLogging,
54+
output_cls=AzOutputProducer,
55+
help_cls=AzCliHelp,
56+
invocation_cls=AzCliCommandInvoker)
5957

6058
self.data['headers'] = {} # the x-ms-client-request-id is generated before a command is to execute
6159
self.data['command'] = 'unknown'

0 commit comments

Comments
 (0)