Update pytest reports generation
- Set workflow step name as junit test suite name - Set HTML report title - Render HTML report all test case rows collapsed - Add tobiko release version and Git commit to reported environment metadata Change-Id: Id827146d1f8455047dd5eedfa90171da8be02ea5
This commit is contained in:
parent
3f3593bf99
commit
7207175342
@ -1,2 +1,3 @@
|
||||
[pytest]
|
||||
junit_family=legacy
|
||||
render_collapsed = True
|
||||
|
@ -15,6 +15,8 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from datetime import datetime
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from oslo_log import log
|
||||
from py.xml import html # pylint: disable=no-name-in-module,import-error
|
||||
@ -23,11 +25,25 @@ import pytest
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
TOX_REPORT_NAME = os.environ.get('TOX_REPORT_NAME', "tobiko_results")
|
||||
|
||||
|
||||
@pytest.hookimpl
|
||||
def pytest_configure(config):
|
||||
configure_metadata(config)
|
||||
configure_caplog(config)
|
||||
configure_timeout(config)
|
||||
configure_junitxml(config)
|
||||
|
||||
|
||||
def configure_metadata(config):
|
||||
# pylint: disable=protected-access
|
||||
from tobiko import version
|
||||
config._metadata["Tobiko Version"] = version.release
|
||||
git_commit = subprocess.check_output(
|
||||
['git', 'log', '-n', '1'],
|
||||
universal_newlines=True).replace('\n', '<br>')
|
||||
config._metadata["Tobiko Git Commit"] = git_commit
|
||||
|
||||
|
||||
def configure_caplog(config):
|
||||
@ -65,6 +81,10 @@ def configure_caplog(config):
|
||||
set_default_inicfg(config, key, default)
|
||||
|
||||
|
||||
def configure_junitxml(config):
|
||||
config.inicfg['junit_suite_name'] = TOX_REPORT_NAME
|
||||
|
||||
|
||||
def set_default_inicfg(config, key, default):
|
||||
value = config.inicfg.setdefault(key, default)
|
||||
if value != default:
|
||||
@ -100,6 +120,10 @@ def pytest_runtest_makereport(item, call): # pylint: disable=unused-argument
|
||||
report.description = str(item.function.__doc__)
|
||||
|
||||
|
||||
def pytest_html_report_title(report):
|
||||
report.title = f"Tobiko test results ({TOX_REPORT_NAME})"
|
||||
|
||||
|
||||
@pytest.hookimpl(hookwrapper=True)
|
||||
def pytest_runtest_call(item):
|
||||
# pylint: disable=protected-access
|
||||
|
@ -55,6 +55,7 @@ def execute(command, *args, **kwargs):
|
||||
universal_newlines = kwargs.pop('universal_newlines', True)
|
||||
check = kwargs.pop('check', True)
|
||||
shell = kwargs.pop('shell', '/bin/bash')
|
||||
environ = kwargs.pop('environ', os.environ)
|
||||
|
||||
if args or kwargs:
|
||||
command = command.format(*args, **kwargs)
|
||||
@ -70,7 +71,8 @@ def execute(command, *args, **kwargs):
|
||||
LOG.info(f"Execute: {command_line}")
|
||||
result = subprocess.run(command_line,
|
||||
stdout=stdout, shell=False,
|
||||
universal_newlines=universal_newlines)
|
||||
universal_newlines=universal_newlines,
|
||||
env=dict(environ))
|
||||
if check:
|
||||
result.check_returncode()
|
||||
return result.stdout
|
||||
|
@ -140,15 +140,18 @@ def run_test_cases():
|
||||
cover_options = ''
|
||||
if TOX_COVER:
|
||||
cover_options = f"--cov=tobiko"
|
||||
|
||||
# Pass environment variables to pytest command
|
||||
environ = dict(os.environ, TOX_REPORT_NAME=TOX_REPORT_NAME)
|
||||
common.execute(f"pytest "
|
||||
f"{xdist_options} "
|
||||
f"{rerun_options} "
|
||||
f"{cover_options} "
|
||||
f"--log-file={TOX_REPORT_LOG} "
|
||||
f"--junitxml={TOX_REPORT_XML} "
|
||||
f"--junit-prefix={TOX_REPORT_NAME} "
|
||||
f"--html={TOX_REPORT_HTML} --self-contained-html "
|
||||
f"{common.get_posargs()}",
|
||||
environ=environ,
|
||||
capture_stdout=False)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user