diff --git a/pytest.ini b/pytest.ini index 5496d4681..89ee67574 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,3 @@ [pytest] junit_family=legacy +render_collapsed = True diff --git a/tobiko/tests/conftest.py b/tobiko/tests/conftest.py index 25e7ce0d7..86220421a 100644 --- a/tobiko/tests/conftest.py +++ b/tobiko/tests/conftest.py @@ -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', '
') + 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 diff --git a/tools/common.py b/tools/common.py index 9013b6974..186a31f3d 100644 --- a/tools/common.py +++ b/tools/common.py @@ -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 diff --git a/tools/run_tests.py b/tools/run_tests.py index 606100305..0c8377fba 100755 --- a/tools/run_tests.py +++ b/tools/run_tests.py @@ -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)