diff options
author | Cédric Ollivier <cedric.ollivier@orange.com> | 2019-11-09 12:28:24 +0100 |
---|---|---|
committer | Cédric Ollivier <cedric.ollivier@orange.com> | 2019-11-09 13:02:54 +0100 |
commit | 728f5c95df4d3edbe6b3f814a270cdf3b532aef9 (patch) | |
tree | b07289945c7bdc6c938ab9dc3b93538a2e6d1feb | |
parent | 7ddcfae7ff8a20fac21f5ba2b923e8e5cbce19e5 (diff) |
Generate Html and Xunit Behave reports
Change-Id: I7d5f31502ba61b61a0b1c885fe8828211bc0bc0a
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r-- | requirements.txt | 1 | ||||
-rw-r--r-- | upper-constraints.txt | 1 | ||||
-rw-r--r-- | xtesting/core/behaveframework.py | 10 | ||||
-rw-r--r-- | xtesting/tests/unit/core/test_behaveframework.py | 35 |
4 files changed, 35 insertions, 12 deletions
diff --git a/requirements.txt b/requirements.txt index d70dba3e..3d583d51 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,7 @@ enum34;python_version=='2.7' or python_version=='2.6' or python_version=='3.3' # requests!=2.20.0 # Apache-2.0 robotframework>=3.0 behave>=1.2.6 +behave-html-formatter>=0.9.4;python_version>='3.5' mock # BSD PrettyTable<0.8 # BSD six # MIT diff --git a/upper-constraints.txt b/upper-constraints.txt index bcf55ebd..1c35e41f 100644 --- a/upper-constraints.txt +++ b/upper-constraints.txt @@ -1,5 +1,6 @@ robotframework===3.1.1 bandit===1.1.0 behave===1.2.6 +behave-html-formatter===0.9.4;python_version>='3.5' pylint===1.9.5;python_version=='2.7' pylint===2.3.1;python_version=='3.7' diff --git a/xtesting/core/behaveframework.py b/xtesting/core/behaveframework.py index 25986f48..ede3883f 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 @@ -102,8 +104,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() diff --git a/xtesting/tests/unit/core/test_behaveframework.py b/xtesting/tests/unit/core/test_behaveframework.py index 70ca9738..c4ab2f7c 100644 --- a/xtesting/tests/unit/core/test_behaveframework.py +++ b/xtesting/tests/unit/core/test_behaveframework.py @@ -10,9 +10,12 @@ """Define the classes required to fully cover behave.""" import logging +import os import unittest import mock +import six + from xtesting.core import behaveframework __author__ = "Deepak Chandella <deepak.chandella@orange.com>" @@ -115,11 +118,17 @@ class RunTesting(unittest.TestCase): self.assertEqual( self.test.run(suites=self.suites, tags=self.tags), self.test.EX_OK) - args[0].assert_called_once_with( - ['--tags=', - '--format=json', - '--outfile={}'.format(self.test.json_file), - 'foo']) + html_file = os.path.join(self.test.res_dir, 'output.html') + args_list = [ + '--tags=', '--junit', + '--junit-directory={}'.format(self.test.res_dir), + '--format=json', '--outfile={}'.format(self.test.json_file)] + if six.PY3: + args_list += [ + '--format=behave_html_formatter:HTMLFormatter', + '--outfile={}'.format(html_file)] + args_list.append('foo') + args[0].assert_called_once_with(args_list) mock_method.assert_called_once_with() @mock.patch('os.makedirs') @@ -143,11 +152,17 @@ class RunTesting(unittest.TestCase): self.test.run( suites=self.suites, tags=self.tags), status) - args[0].assert_called_once_with( - ['--tags=', - '--format=json', - '--outfile={}'.format(self.test.json_file), - 'foo']) + html_file = os.path.join(self.test.res_dir, 'output.html') + args_list = [ + '--tags=', '--junit', + '--junit-directory={}'.format(self.test.res_dir), + '--format=json', '--outfile={}'.format(self.test.json_file)] + if six.PY3: + args_list += [ + '--format=behave_html_formatter:HTMLFormatter', + '--outfile={}'.format(html_file)] + args_list.append('foo') + args[0].assert_called_once_with(args_list) args[1].assert_called_once_with(self.test.res_dir) def test_parse_results_exc(self): |