Skip to content

Commit

Permalink
Improve subprocess_run about stderr
Browse files Browse the repository at this point in the history
Change the implementation to behave more similarly in case of pass or
fail.
  • Loading branch information
mpagot committed Jul 5, 2024
1 parent 9047b79 commit d7b9b3a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions scripts/qesap/lib/process_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ def subprocess_run(cmd, env=None):
log.info("with env %s", env)

proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=False, env=env)

ret_stdout = list(proc.stdout.decode('UTF-8').splitlines())
if proc.returncode != 0:
log.error("ERROR %d in %s", proc.returncode, ' '.join(cmd[0:1]))
for line in proc.stdout.decode('UTF-8').splitlines():
log.error("OUTPUT: %s", line)
return (proc.returncode, [])
stdout = [line.decode("utf-8") for line in proc.stdout.splitlines()]

for line in stdout:
log.debug('OUTPUT: %s', line)
return (0, stdout)
for line in ret_stdout:
if proc.returncode != 0:
log.error("OUTPUT: %s", line)
else:
log.debug('OUTPUT: %s', line)
return (proc.returncode, ret_stdout)
4 changes: 2 additions & 2 deletions scripts/qesap/test/unit/test_subprocess_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_stderr():
test_text = '"Banana"'
exit_code, stdout_list = subprocess_run(['logger', '-s', test_text])
assert exit_code == 0
assert stdout_list != []
assert len(stdout_list) > 0


def test_err():
Expand All @@ -53,7 +53,7 @@ def test_err():

exit_code, stdout_list = subprocess_run(['cat', not_existing_file])
assert exit_code == 1
assert stdout_list == []
assert len(stdout_list) > 0


def test_env():
Expand Down

0 comments on commit d7b9b3a

Please sign in to comment.