Skip to content

Commit 8dff97c

Browse files
committed
Add test for call_subprocess stdout_only
1 parent de11340 commit 8dff97c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/unit/test_utils_subprocess.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
format_command_args,
1515
make_command,
1616
make_subprocess_output_error,
17+
subprocess_logger,
1718
)
1819

1920

@@ -154,6 +155,35 @@ def test_make_subprocess_output_error__non_ascii_line():
154155
assert actual == expected, u'actual: {}'.format(actual)
155156

156157

158+
@pytest.mark.parametrize(
159+
('stdout_only', 'expected'),
160+
[
161+
(True, ("out\n", "out\r\n")),
162+
(False, ("out\nerr\n", "out\r\nerr\r\n", "err\nout\n", "err\r\nout\r\n")),
163+
],
164+
)
165+
def test_call_subprocess_stdout_only(capfd, monkeypatch, stdout_only, expected):
166+
log = []
167+
monkeypatch.setattr(subprocess_logger, "debug", lambda *args: log.append(args[0]))
168+
out = call_subprocess(
169+
[
170+
sys.executable,
171+
"-c",
172+
"import sys; "
173+
"sys.stdout.write('out\\n'); "
174+
"sys.stderr.write('err\\n')"
175+
],
176+
stdout_only=stdout_only,
177+
)
178+
assert out in expected
179+
captured = capfd.readouterr()
180+
assert captured.err == ""
181+
assert (
182+
log == ["Running command %s", "out", "err"]
183+
or log == ["Running command %s", "err", "out"]
184+
)
185+
186+
157187
class FakeSpinner(SpinnerInterface):
158188

159189
def __init__(self):

0 commit comments

Comments
 (0)