From 5604c8aad4edc2877bbd77927e323f87fc434c2c Mon Sep 17 00:00:00 2001 From: Oleksandr Kyrylchuk Date: Fri, 17 Apr 2015 13:41:38 +0300 Subject: [PATCH] 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 --- .../common/object_descriptors.py | 13 ++++++++++--- .../validation_plugin/fuel_health/__init__.py | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/cloudv_ostf_adapter/common/object_descriptors.py b/cloudv_ostf_adapter/common/object_descriptors.py index 1a7d04b..6d602e2 100644 --- a/cloudv_ostf_adapter/common/object_descriptors.py +++ b/cloudv_ostf_adapter/common/object_descriptors.py @@ -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): diff --git a/cloudv_ostf_adapter/validation_plugin/fuel_health/__init__.py b/cloudv_ostf_adapter/validation_plugin/fuel_health/__init__.py index 5888f50..0791ad4 100644 --- a/cloudv_ostf_adapter/validation_plugin/fuel_health/__init__.py +++ b/cloudv_ostf_adapter/validation_plugin/fuel_health/__init__.py @@ -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"