Properly teardown subprocesses when testing

This commit is contained in:
Simon Gomizelj 2018-02-08 14:45:18 -05:00
parent 7cf23fabc4
commit 7b87d42221

View File

@ -37,19 +37,9 @@ def run_cmd(cmd, stdin_data=None, expect=0, dontwritebytecode=False):
universal_newlines=True, universal_newlines=True,
shell=False, shell=False,
env=env) env=env)
if stdin_data is not None: output = p.communicate(input=stdin_data)
p.stdin.write(stdin_data) assert p.wait() == expect
p.stdin.flush() return output
p.stdin.close()
# Read stdout and stderr otherwise if the PIPE buffer is full, we might
# wait for ever…
stdout = ""
stderr = ""
while p.poll() is None:
stdout += p.stdout.read()
stderr += p.stderr.read()
assert p.returncode == expect
return stdout, stderr
def rm(fpath): def rm(fpath):