Skip to content

Commit 73ab143

Browse files
committed
[pytest]: print out stdout/stderr message when cmd fails (#1188)
1 parent 1883c0a commit 73ab143

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

tests/conftest.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
from swsscommon import swsscommon
1515

1616
def ensure_system(cmd):
17-
rc = os.WEXITSTATUS(os.system(cmd))
17+
(rc, output) = commands.getstatusoutput(cmd)
1818
if rc:
19-
raise RuntimeError('Failed to run command: %s' % cmd)
19+
raise RuntimeError('Failed to run command: %s. rc=%d. output: %s' % (cmd, rc, output))
2020

2121
def pytest_addoption(parser):
2222
parser.addoption("--dvsname", action="store", default=None,
@@ -214,7 +214,7 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None):
214214

215215
# mount redis to base to unique directory
216216
self.mount = "/var/run/redis-vs/{}".format(self.ctn_sw.name)
217-
os.system("mkdir -p {}".format(self.mount))
217+
ensure_system("mkdir -p {}".format(self.mount))
218218

219219
self.environment = ["fake_platform={}".format(fakeplatform)] if fakeplatform else []
220220

@@ -385,15 +385,15 @@ def get_logs(self, modname=None):
385385
else:
386386
log_dir = "log/{}".format(modname)
387387
os.system("rm -rf {}".format(log_dir))
388-
os.system("mkdir -p {}".format(log_dir))
388+
ensure_system("mkdir -p {}".format(log_dir))
389389
p = subprocess.Popen(["tar", "--no-same-owner", "-C", "./{}".format(log_dir), "-x"], stdin=subprocess.PIPE)
390390
for x in stream:
391391
p.stdin.write(x)
392392
p.stdin.close()
393393
p.wait()
394394
if p.returncode:
395395
raise RuntimeError("Failed to unpack the archive.")
396-
os.system("chmod a+r -R log")
396+
ensure_system("chmod a+r -R log")
397397

398398
def add_log_marker(self, file=None):
399399
marker = "=== start marker {} ===".format(datetime.now().isoformat())

0 commit comments

Comments
 (0)