aboutsummaryrefslogtreecommitdiffstats
path: root/xtesting/core/behaveframework.py
diff options
context:
space:
mode:
Diffstat (limited to 'xtesting/core/behaveframework.py')
-rw-r--r--xtesting/core/behaveframework.py40
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()