Skip to content

Commit

Permalink
[pytest]: print out stdout/stderr message when cmd fails (#1188)
Browse files Browse the repository at this point in the history
  • Loading branch information
lguohan committed Jan 30, 2020
1 parent 1883c0a commit 73ab143
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from swsscommon import swsscommon

def ensure_system(cmd):
rc = os.WEXITSTATUS(os.system(cmd))
(rc, output) = commands.getstatusoutput(cmd)
if rc:
raise RuntimeError('Failed to run command: %s' % cmd)
raise RuntimeError('Failed to run command: %s. rc=%d. output: %s' % (cmd, rc, output))

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

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

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

Expand Down Expand Up @@ -385,15 +385,15 @@ def get_logs(self, modname=None):
else:
log_dir = "log/{}".format(modname)
os.system("rm -rf {}".format(log_dir))
os.system("mkdir -p {}".format(log_dir))
ensure_system("mkdir -p {}".format(log_dir))
p = subprocess.Popen(["tar", "--no-same-owner", "-C", "./{}".format(log_dir), "-x"], stdin=subprocess.PIPE)
for x in stream:
p.stdin.write(x)
p.stdin.close()
p.wait()
if p.returncode:
raise RuntimeError("Failed to unpack the archive.")
os.system("chmod a+r -R log")
ensure_system("chmod a+r -R log")

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

0 comments on commit 73ab143

Please sign in to comment.