Skip to content

Commit e0887a8

Browse files
authored
Fix env=None introduced in #572 (#601)
1 parent 040ee6c commit e0887a8

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

aws_gate/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ def execute(cmd, args, **kwargs):
126126
ret, result = None, None
127127

128128
env_path = DEFAULT_GATE_BIN_PATH + os.pathsep + os.environ["PATH"]
129-
env = os.environ.copy().update({"PATH": env_path})
129+
env = os.environ.copy()
130+
env.update({"PATH": env_path})
130131
try:
132+
logger.debug('PATH in environment: "%s"', os.environ["PATH"])
131133
logger.debug('Executing "%s"', " ".join([cmd] + args))
132134
result = subprocess.run([cmd] + args, env=env, check=True, **kwargs)
133135
except subprocess.CalledProcessError as e:

tests/unit/test_utils.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import errno
22
import os
3-
import subprocess
4-
from subprocess import PIPE
5-
63
import pytest
7-
from botocore import credentials
8-
from botocore.exceptions import ClientError
9-
from hypothesis import given
10-
from hypothesis.strategies import lists, text
11-
4+
import subprocess
125
from aws_gate import __version__
6+
from aws_gate.constants import DEFAULT_GATE_BIN_PATH
137
from aws_gate.exceptions import AWSConnectionError
148
from aws_gate.utils import (
159
is_existing_profile,
@@ -23,6 +17,11 @@
2317
fetch_instance_details_from_config,
2418
get_instance_details,
2519
)
20+
from botocore import credentials
21+
from botocore.exceptions import ClientError
22+
from hypothesis import given
23+
from hypothesis.strategies import lists, text
24+
from subprocess import PIPE
2625

2726

2827
# pylint: disable=too-few-public-methods
@@ -138,6 +137,16 @@ def test_execute(mocker, cmd, args):
138137
assert execute(cmd, args) == "output"
139138

140139

140+
def test_execute_environment(mocker):
141+
mock_output = mocker.MagicMock(stdout=b"output")
142+
m = mocker.patch("aws_gate.utils.subprocess.run", return_value=mock_output)
143+
144+
execute("ls", ["-l"])
145+
146+
assert m.call_args_list[0][1]["env"] is not None
147+
assert DEFAULT_GATE_BIN_PATH in m.call_args_list[0][1]["env"]["PATH"]
148+
149+
141150
def test_execute_command_exited_with_nonzero_rc(mocker):
142151
mock = mocker.patch(
143152
"aws_gate.utils.subprocess.run",

0 commit comments

Comments
 (0)