diff --git a/docs/releases.rst b/docs/releases.rst index 75197aa1fc..f080ed05fe 100644 --- a/docs/releases.rst +++ b/docs/releases.rst @@ -4,6 +4,16 @@ Releases ====================== +tmt-1.XX.0 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The :ref:`/plugins/report/junit` report plugin now supports a new +``subresults`` JUnit flavor. This flavor adds support for tmt subresults and +changes the level of ```` and ```` tags. By using this +flavor, the ``tmt.Result`` tags become ```` tags with one +```` tag representing the parent result, and possible additional +```` tags for each ``tmt.result.SubResult``. + tmt-1.38.0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/report/junit/test.sh b/tests/report/junit/test.sh index 03612f8426..83b33647eb 100755 --- a/tests/report/junit/test.sh +++ b/tests/report/junit/test.sh @@ -79,8 +79,22 @@ rlJournalStart rlAssertGrep '' "custom-subresults-template-out.xml" rlAssertGrep '' "custom-subresults-template-out.xml" + rlPhaseStartTest "[$method] Check the 'subresults' flavor" + rlRun "tmt run -avr execute -h $method report -h junit --file subresults-out.xml --flavor subresults 2>&1 >/dev/null | tee output" 2 + + # Parent result recorded in testuite tag + rlAssertGrep '' "subresults-out.xml" + rlAssertGrep '' "subresults-out.xml" + + # TODO: Add check for additional subresults as soon as they get saved by: + # - https://github.com/teemtee/tmt/pull/3200 rlPhaseEnd done diff --git a/tmt/steps/report/junit.py b/tmt/steps/report/junit.py index 3b4694c5bb..d586c212a8 100644 --- a/tmt/steps/report/junit.py +++ b/tmt/steps/report/junit.py @@ -389,7 +389,7 @@ class ReportJUnitData(tmt.steps.report.ReportStepData): flavor: str = field( default=DEFAULT_FLAVOR_NAME, option='--flavor', - choices=[DEFAULT_FLAVOR_NAME, CUSTOM_FLAVOR_NAME], + choices=[DEFAULT_FLAVOR_NAME, CUSTOM_FLAVOR_NAME, 'subresults'], help='Name of a JUnit flavor to generate.') template_path: Optional[Path] = field( diff --git a/tmt/steps/report/junit/schemas/subresults.xsd b/tmt/steps/report/junit/schemas/subresults.xsd new file mode 100644 index 0000000000..803c09c215 --- /dev/null +++ b/tmt/steps/report/junit/schemas/subresults.xsd @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tmt/steps/report/junit/templates/subresults.xml.j2 b/tmt/steps/report/junit/templates/subresults.xml.j2 new file mode 100644 index 0000000000..f71f2e34a8 --- /dev/null +++ b/tmt/steps/report/junit/templates/subresults.xml.j2 @@ -0,0 +1,80 @@ +{% extends "_base.xml.j2" %} + +{# + This flavor changes the level of `` and `` tags. The + `tmt.Result` becomes ```` instead of ``testcase`` and + ```` tags become ``tmt.SubResult``. +#} + +{% block content %} + + + {% block testsuites %} + {% for result in RESULTS %} + {% set main_log = result.log | first | read_log %} + {% set main_log_failures = main_log | failures | e %} + {% set main_test_duration = result.duration | duration_to_seconds %} + + {# TODO: Fix the test counts in testsuite tag #} + {# TODO: Also fix the counts because now with an additional testcase for parent results, the counts will not match. #} + + + + {# + Always include a `testcase` representing the main result. + The `error/failure/skipped` tags must not exists inside a + `testsuite`, they are only allowed inside of a `testcase`. + #} + + {% if result.result.value == 'error' or result.result.value == 'warn' %} + {{ main_log_failures }} + {% elif result.result.value == 'fail' %} + {{ main_log_failures }} + {% elif result.result.value == 'info' %} + {{ main_log_failures }} + {% endif %} + + {% if INCLUDE_OUTPUT_LOG and main_log %} + {{ main_log | e }} + {% endif %} + + + {% for subresult in result.subresult %} + {% set subresult_log = subresult.log | first | read_log %} + {% set subresult_log_failures = main_log | failures | e %} + {% set subresult_test_duration = subresult.duration | duration_to_seconds %} + + + {% if subresult.result.value == 'error' or subresult.result.value == 'warn' %} + {{ subresult_log_failures }} + {% elif subresult.result.value == 'fail' %} + {{ subresult_log_failures }} + {% elif subresult.result.value == 'info' %} + {{ subresult_log_failures }} + {% endif %} + + {% if INCLUDE_OUTPUT_LOG and subresult_log %} + {{ subresult_log | e }} + {% endif %} + + {% endfor %} + + {# Optionally add the result properties #} + {% if result.properties is defined %} + {% with properties=result.properties %} + {% include "includes/_properties.xml.j2" %} + {% endwith %} + {% endif %} + + {% endfor %} + {% endblock %} + + {# Optionally include the properties section in testsuites tag #} + {% if RESULTS.properties is defined %} + {% with properties=RESULTS.properties %} + {% include "includes/_properties.xml.j2" %} + {% endwith %} + {% endif %} + + +{% endblock %}