diff options
author | 2019-11-09 12:28:24 +0100 | |
---|---|---|
committer | 2021-02-09 19:22:35 +0100 | |
commit | f772dee4da63faddd34fcaf8a9c97b1c67d9dfe9 (patch) | |
tree | dfde600527ea50653e978df65e283cf9e792cf5c /xtesting/core | |
parent | 115092d35fdf9b449ff91e36cc2d668d39a8b257 (diff) |
Generate Html and Xunit Behave reports
Change-Id: I7d5f31502ba61b61a0b1c885fe8828211bc0bc0a
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
(cherry picked from commit 728f5c95df4d3edbe6b3f814a270cdf3b532aef9)
Diffstat (limited to 'xtesting/core')
-rw-r--r-- | xtesting/core/behaveframework.py | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/xtesting/core/behaveframework.py b/xtesting/core/behaveframework.py index d8a61ef3..2b41614c 100644 --- a/xtesting/core/behaveframework.py +++ b/xtesting/core/behaveframework.py @@ -14,7 +14,9 @@ from __future__ import division import logging import os import time + import json +import six from behave.__main__ import main as behave_main @@ -32,7 +34,6 @@ class BehaveFramework(testcase.TestCase): def __init__(self, **kwargs): super(BehaveFramework, self).__init__(**kwargs) - self.res_dir = os.path.join(self.dir_results, self.case_name) self.json_file = os.path.join(self.res_dir, 'output.json') self.total_tests = 0 self.pass_tests = 0 @@ -42,14 +43,8 @@ class BehaveFramework(testcase.TestCase): def parse_results(self): """Parse output.json and get the details in it.""" - - try: - with open(self.json_file) as stream_: - self.response = json.load(stream_) - except IOError: - self.__logger.error("Error reading the file %s", self.json_file) - - try: + with open(self.json_file) as stream_: + self.response = json.load(stream_) if self.response: self.total_tests = len(self.response) for item in self.response: @@ -59,21 +54,14 @@ class BehaveFramework(testcase.TestCase): self.fail_tests += 1 elif item['status'] == 'skipped': self.skip_tests += 1 - except KeyError: - self.__logger.error("Error in json - %s", self.response) - - try: self.result = 100 * ( self.pass_tests / self.total_tests) - except ZeroDivisionError: - self.__logger.error("No test has been run") - - self.details = {} - self.details['total_tests'] = self.total_tests - self.details['pass_tests'] = self.pass_tests - self.details['fail_tests'] = self.fail_tests - self.details['skip_tests'] = self.skip_tests - self.details['tests'] = self.response + self.details = {} + self.details['total_tests'] = self.total_tests + self.details['pass_tests'] = self.pass_tests + self.details['fail_tests'] = self.fail_tests + self.details['skip_tests'] = self.skip_tests + self.details['tests'] = self.response def run(self, **kwargs): """Run the BehaveFramework feature files @@ -103,8 +91,12 @@ class BehaveFramework(testcase.TestCase): self.__logger.exception("Cannot create %s", self.res_dir) return self.EX_RUN_ERROR config = ['--tags='+','.join(tags), - '--format=json', - '--outfile='+self.json_file] + '--junit', '--junit-directory={}'.format(self.res_dir), + '--format=json', '--outfile={}'.format(self.json_file)] + if six.PY3: + html_file = os.path.join(self.res_dir, 'output.html') + config += ['--format=behave_html_formatter:HTMLFormatter', + '--outfile={}'.format(html_file)] for feature in suites: config.append(feature) self.start_time = time.time() |