Add tests errors as details. #266

Merged
merged 1 commit into from Jan 27, 2016
Jump to file or symbol
Failed to load files and symbols.
+35 −13
Split
View
@@ -24,6 +24,7 @@
import time
import testscenarios
+from testtools import content
logger = logging.getLogger(__name__)
@@ -70,7 +71,8 @@ def _run_command_through_ssh(ip, port, user, command):
ssh_command = ['ssh', '-l', user, '-p', port, ip]
ssh_command.extend(_get_ssh_options())
ssh_command.extend(command)
- return subprocess.check_output(ssh_command).decode("utf-8")
+ return subprocess.check_output(
+ ssh_command, stderr=subprocess.STDOUT, universal_newlines=True)
def _get_ssh_options():
@@ -230,17 +232,32 @@ def tearDownClass(cls):
cls.vm_process.kill()
shutil.rmtree(cls.temp_dir)
- def run_command_through_ssh(self, command):
- return _run_command_through_ssh(
- self.testbed_ip, self.testbed_port, 'ubuntu', command)
-
- def build_snap(self, project_dir):
+ def setUp(self):
+ super().setUp()
# To measure coverage, a wrapper for the snapcraft binary might be set
# in the environment variable.
snapcraft_bin = os.getenv('SNAPCRAFT', 'snapcraft')
- snapcraft = os.path.join(os.getcwd(), 'bin', snapcraft_bin)
- subprocess.check_call([snapcraft, 'clean'], cwd=project_dir)
- subprocess.check_call([snapcraft, 'snap'], cwd=project_dir)
+ self.snapcraft_command = os.path.join(
+ os.getcwd(), 'bin', snapcraft_bin)
+
+ def run_command_through_ssh(self, command):
+ try:
+ return _run_command_through_ssh(
+ self.testbed_ip, self.testbed_port, 'ubuntu', command)
+ except subprocess.CalledProcessError as e:
+ self.addDetail('ssh output', content.text_content(e.output))
+ raise
+
+ def build_snap(self, project_dir):
+ subprocess.check_call(
+ [self.snapcraft_command, 'clean'], cwd=project_dir)
+ try:
+ subprocess.check_output(
+ [self.snapcraft_command, 'snap'], cwd=project_dir,
+ stderr=subprocess.STDOUT, universal_newlines=True)
+ except subprocess.CalledProcessError as e:
+ self.addDetail('output', content.text_content(e.output))
+ raise
def copy_snap_to_testbed(self, snap_local_path):
_copy_file_through_ssh(
@@ -1,6 +1,6 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
-# Copyright (C) 2015 Canonical Ltd
+# Copyright (C) 2015, 2016 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
@@ -19,6 +19,7 @@
import shutil
import testtools
+from testtools import content
from snapcraft.tests import fixture_setup
@@ -46,9 +47,13 @@ def run_snapcraft(self, command, project_dir=None):
cwd = os.path.join(self.path, project_dir)
else:
cwd = None
- return subprocess.check_output(
- [self.snapcraft_command] + command, cwd=cwd,
- stderr=subprocess.STDOUT, universal_newlines=True)
+ try:
+ return subprocess.check_output(
+ [self.snapcraft_command] + command, cwd=cwd,
+ stderr=subprocess.STDOUT, universal_newlines=True)
+ except subprocess.CalledProcessError as e:
+ self.addDetail('output', content.text_content(e.output))
+ raise
def copy_project_to_tmp(self, project_dir):
tmp_project_dir = os.path.join(self.path, project_dir)