summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2017-05-11 10:03:47 +0200
committerCédric Ollivier <cedric.ollivier@orange.com>2017-05-11 13:45:23 +0200
commit648d31af02248b8b2da059e228c10f1e3f81eb5b (patch)
treebd52f9c24facd70134e0a083d3a20aceca3b4939
parent5b536321b8722f87715cab7bae3f6813bb73fd2a (diff)
Modify TestCase.__str__() to use PrettyTable
It adds PrettyTable as requirement even if it's already defined in OpenStack client dependencies. If the TestCase object is considered as invalid, it simply returns the default str. Change-Id: Iee788aef2a13694d9482560977cbbf21c7f2c967 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r--functest/core/testcase.py16
-rw-r--r--functest/tests/unit/core/test_testcase.py6
-rw-r--r--requirements.txt1
-rw-r--r--test-requirements.txt1
4 files changed, 16 insertions, 8 deletions
diff --git a/functest/core/testcase.py b/functest/core/testcase.py
index 49fae6097..317c4f59e 100644
--- a/functest/core/testcase.py
+++ b/functest/core/testcase.py
@@ -12,6 +12,8 @@
import logging
import os
+import prettytable
+
import functest.utils.functest_utils as ft_utils
__author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
@@ -49,14 +51,16 @@ class TestCase(object):
assert self.case_name
result = 'PASS' if(self.is_successful(
) == TestCase.EX_OK) else 'FAIL'
- return ('| {0:<23} | {1:<13} | {2:<10} | {3:<13} |'
- '\n{4:-<26}{4:-<16}{4:-<13}{4:-<16}{4}'.format(
- self.case_name, self.project_name,
- self.get_duration(), result, '+'))
+ msg = prettytable.PrettyTable(
+ header_style='upper',
+ field_names=['test case', 'project', 'duration',
+ 'result'])
+ msg.add_row([self.case_name, self.project_name,
+ self.get_duration(), result])
+ return msg.get_string()
except AssertionError:
self.__logger.error("We cannot print invalid objects")
- return '| {0:^68} |\n{1:-<26}{1:-<16}{1:-<13}{1:-<16}{1}'.format(
- 'INVALID OBJECT', '+')
+ return super(TestCase, self).__str__()
def get_duration(self):
"""Return the duration of the test case.
diff --git a/functest/tests/unit/core/test_testcase.py b/functest/tests/unit/core/test_testcase.py
index b25ce2260..08a717a29 100644
--- a/functest/tests/unit/core/test_testcase.py
+++ b/functest/tests/unit/core/test_testcase.py
@@ -191,11 +191,13 @@ class TestCaseTesting(unittest.TestCase):
def test_str_project_name_ko(self):
self.test.project_name = None
- self.assertIn("INVALID OBJECT", str(self.test))
+ self.assertIn("<functest.core.testcase.TestCase object at",
+ str(self.test))
def test_str_case_name_ko(self):
self.test.case_name = None
- self.assertIn("INVALID OBJECT", str(self.test))
+ self.assertIn("<functest.core.testcase.TestCase object at",
+ str(self.test))
def test_str_pass(self):
duration = '01:01'
diff --git a/requirements.txt b/requirements.txt
index e709220a5..59274ecf0 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -33,3 +33,4 @@ click==6.6
openbaton-cli==2.2.1-beta7
mock==1.3.0
iniparse==0.4
+PrettyTable>=0.7.1,<0.8 # BSD
diff --git a/test-requirements.txt b/test-requirements.txt
index 471e9c30a..f68a56f0a 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -26,3 +26,4 @@ robotframework-requests==0.3.8
robotframework-sshlibrary==2.1.1
subprocess32==3.2.7
virtualenv==15.1.0
+PrettyTable>=0.7.1,<0.8 # BSD