podman-compose/tests/test_utils.py
Povilas Kanapickas f4dc5f3b93 tests: Print output in case subprocess returns unexpected code
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 13:14:02 +02:00

25 lines
715 B
Python

# SPDX-License-Identifier: GPL-2.0
import subprocess
class RunSubprocessMixin:
def run_subprocess(self, args):
proc = subprocess.Popen(
args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
out, err = proc.communicate()
return out, err, proc.returncode
def run_subprocess_assert_returncode(self, args, expected_returncode=0):
out, err, returncode = self.run_subprocess(args)
self.assertEqual(
returncode,
expected_returncode,
f"Invalid return code of process {returncode} != {expected_returncode}\n"
f"stdout: {out}\nstderr: {err}\n",
)
return out, err