bdd: move external process execution in separate func

This commit is contained in:
Sarah Hoffmann
2021-01-04 19:58:59 +01:00
parent faa85ded50
commit 72587b08fa
3 changed files with 28 additions and 30 deletions

22
test/bdd/steps/utils.py Normal file
View File

@@ -0,0 +1,22 @@
"""
Various smaller helps for step execution.
"""
import logging
import subprocess
LOG = logging.getLogger(__name__)
def run_script(cmd, **kwargs):
""" Run the given command, check that it is successful and output
when necessary.
"""
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
**kwargs)
(outp, outerr) = proc.communicate()
outp = outp.decode('utf-8')
outerr = outerr.decode('utf-8').replace('\\n', '\n')
LOG.debug("Run command: %s\n%s\n%s", cmd, outp, outerr)
assert proc.returncode == 0, "Script '{}' failed:\n{}\n{}\n".format(cmd[0], outp, outerr)
return outp, outerr