Browse Source

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
changes/04/773704/4
Federico Ressi 4 months ago
parent
commit
7207175342
4 changed files with 32 additions and 2 deletions
  1. +1
    -0
      pytest.ini
  2. +24
    -0
      tobiko/tests/conftest.py
  3. +3
    -1
      tools/common.py
  4. +4
    -1
      tools/run_tests.py

+ 1
- 0
pytest.ini View File

@ -1,2 +1,3 @@
[pytest]
junit_family=legacy
render_collapsed = True

+ 24
- 0
tobiko/tests/conftest.py View File

@ -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


+ 3
- 1
tools/common.py View File

@ -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


+ 4
- 1
tools/run_tests.py View File

@ -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…
Cancel
Save