Properly teardown subprocesses when testing
This commit is contained in:
parent
7cf23fabc4
commit
7b87d42221
@ -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):
|
||||||
|
Loading…
Reference in New Issue
Block a user