From f3b835a57be5503461b2d4ff333c969c947e4024 Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Thu, 23 May 2019 12:36:13 +0200 Subject: [PATCH] Add tox environment to generate HTML test case reports. By typing below commands it generates HTML report file of Python test case results: tox -e report It generates 'report/build/testr_results.html' file. To run test cases (for example scenario tests) and produce report HTML file it is possible to chain tox environment names in a list. For example: tox -e scenario,report Or simply: tox -e scenario tox -e report This new environment is intended to be used in CI jobs to produce reports after verifications. Change-Id: I63d4d2977fb5b2c868361aa00db0e1334f33fa10 --- report/.gitignore | 1 + report/build.sh | 19 +++++++++++++++++++ report/requirements.txt | 4 ++++ tox.ini | 8 +++++++- 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 report/.gitignore create mode 100755 report/build.sh create mode 100644 report/requirements.txt diff --git a/report/.gitignore b/report/.gitignore new file mode 100644 index 000000000..84c048a73 --- /dev/null +++ b/report/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/report/build.sh b/report/build.sh new file mode 100755 index 000000000..7919c2512 --- /dev/null +++ b/report/build.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +# Produce test HTML report file into ${REPORT_DIR} + +set -xeu + + +TESTR_DIR=${TESTR_DIR:-$(pwd)} +BUILD_DIR=${BUILD_DIR:-${TESTR_DIR}/report/build} +SUBUNIT_FILE=${SUBUNIT_FILE:-${BUILD_DIR}/last.subunit} +TESTR_RESULTS_HTML=${TESTR_RESULTS_HTML:-${BUILD_DIR}/testr_results.html} + +make_testr_results_html() { + mkdir -p "$(dirname ${SUBUNIT_FILE})" + (cd "${TESTR_DIR}" && stestr last --subunit) > "${SUBUNIT_FILE}" + (cd "${BUILD_DIR}" && subunit2html "${SUBUNIT_FILE}" "${TESTR_RESULTS_HTML}") +} + +make_testr_results_html diff --git a/report/requirements.txt b/report/requirements.txt new file mode 100644 index 000000000..2d450a513 --- /dev/null +++ b/report/requirements.txt @@ -0,0 +1,4 @@ +# Requirements file for 'report' Tox environment + +os-testr>=1.0 # Apache 2.0 +stestr>=2.0 # Apache-2.0 diff --git a/tox.ini b/tox.ini index 5b60509d8..60027f663 100644 --- a/tox.ini +++ b/tox.ini @@ -143,7 +143,7 @@ whitelist_externals = * commands = {posargs} -# --- documentation environments --------------------------------------------- +# --- documentation environments ---------------------------------------------- [testenv:docs] @@ -169,3 +169,9 @@ deps = {[testenv:docs]deps} commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html + +# --- CI report environments -------------------------------------------------- + +[testenv:report] +deps = -r {toxinidir}/report/requirements.txt +commands = {toxinidir}/report/build.sh