Added functionality for short test caption in CLI

Reasons:
    - Names of tests shown in CLI output are too long to fit the window
      frame size sometimes
Changes:
    - Added functionality that extracts short test description from report
      if test succeded or just its class name and test name otherwise and
      returns as a test name for CLI

Implements blueprint: test-caption

Change-Id: Id0d7124e24d364f8be0e522002296a367b595156
This commit is contained in:
Oleksandr Kyrylchuk 2015-04-17 13:41:38 +03:00
parent ca2fe0c554
commit 5604c8aad4
2 changed files with 28 additions and 3 deletions

View File

@ -17,7 +17,7 @@ from oslo_utils import importutils
class Test(object):
"""
This class represents seginificant information about test case
This class represents siginificant information about test case
such as:
test
its execution report
@ -41,6 +41,9 @@ class Test(object):
@type test_class: basestring
"""
self._test_class = test_class
self._test_caption = test_class
self._duration = None
self._report = None
self._result = None
@ -60,7 +63,7 @@ class Test(object):
:rtype: dict
"""
return {
'test': self._test_class,
'test': self._test_caption,
'report': self.report,
'result': self.result,
'duration': self.duration,
@ -82,7 +85,11 @@ class Test(object):
"""
Returns nose test name
"""
return self._test_class
return self._test_caption
@name.setter
def name(self, name):
self._test_caption = name
@property
def report(self):

View File

@ -89,6 +89,14 @@ class FuelHealthPlugin(base.ValidationPlugin):
if line.startswith("Ran"):
return line.split(" ")[-1]
def _get_test_name_from_report(self, report):
if len(report) and not report[0].startswith('ERROR'):
return report[0]
return ''
def _get_test_name_from_class(self, cls_name):
return cls_name.split(':')[1]
def _execute_and_report(self, test_suite_paths):
"""
Executes and assembles report right after each test execution
@ -106,6 +114,16 @@ class FuelHealthPlugin(base.ValidationPlugin):
test_descr = object_descriptors.Test(test)
test_descr.report = "".join(suites_report.buflist)
# @TODO(okyrylchuk): there's no way to extract test
# description from report when test fails, so it should
# be implemented in a rather different way
_name = self._get_test_name_from_report(suites_report.buflist)
_name = _name or self._get_test_name_from_class(test_descr.name)
test_descr.name = _name
test_descr.duration = self._get_duration_from_report(
suites_report.buflist)
test_descr.result = "Passed" if result else "Failed"