Skip to content

Commit

Permalink
Generate XUnit Polarion flavor using JUnit report plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
seberm committed Aug 27, 2024
1 parent 9a61dd4 commit 96702c5
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 56 deletions.
6 changes: 3 additions & 3 deletions tests/report/polarion/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ rlJournalStart
rlRun "tmt run -avr execute report -h polarion --project-id RHELBASEOS --no-upload --planned-in RHEL-9.1.0 --file xunit.xml 2>&1 >/dev/null | tee output" 2
rlAssertGrep "1 test passed, 1 test failed and 1 error" "output"
rlAssertGrep '<testsuite name="/plan" disabled="0" errors="1" failures="1" skipped="0" tests="3"' "xunit.xml"
rlAssertGrep '<property name="polarion-project-id" value="RHELBASEOS" />' "xunit.xml"
rlAssertGrep '<property name="polarion-testcase-id" value="BASEOS-10914" />' "xunit.xml"
rlAssertGrep '<property name="polarion-custom-plannedin" value="RHEL-9.1.0" />' "xunit.xml"
rlAssertGrep '<property name="polarion-project-id" value="RHELBASEOS"/>' "xunit.xml"
rlAssertGrep '<property name="polarion-testcase-id" value="BASEOS-10914"/>' "xunit.xml"
rlAssertGrep '<property name="polarion-custom-plannedin" value="RHEL-9.1.0"/>' "xunit.xml"
rlAssertGrep "Maximum test time '2s' exceeded." "xunit.xml"
rlPhaseEnd

Expand Down
3 changes: 2 additions & 1 deletion tmt/steps/report/junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def _read_log(log: Path) -> str:
xml_data = render_template_file(
template_path,
environment,
FLAVOR=flavor,
RESULTS=results_context,
PLAN=phase.step.plan,
INCLUDE_OUTPUT_LOG=include_output_log,
Expand Down Expand Up @@ -259,7 +260,7 @@ class ReportJUnitData(tmt.steps.report.ReportStepData):
default=DEFAULT_FLAVOR_NAME,
option='--flavor',
metavar='FLAVOR',
choices=[DEFAULT_FLAVOR_NAME, CUSTOM_FLAVOR_NAME],
choices=[DEFAULT_FLAVOR_NAME, CUSTOM_FLAVOR_NAME, 'polarion'],
help=f"Name of a JUnit flavor to generate. By default, the '{DEFAULT_FLAVOR_NAME}' flavor "
"is used.")

Expand Down
97 changes: 97 additions & 0 deletions tmt/steps/report/junit/schemas/polarion.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8" ?>

<!--
This schema supports only a subset of the features provided by the
`xml-junit` library. Additionally, many attributes are explicitly set as
required. This is intentional to limit the currently supported features of
the TMT Polarion report plugin .
The Polarion `xunit.xml` is almost the same as default output of junit
report plugin but it must allow definition of `properties` inside of
`testsuites` (NOT `testsuite`) and `testcase`.
-->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="failure">
<xs:complexType mixed="true">
<xs:attribute name="type" type="xs:string" use="required"/>
<xs:attribute name="message" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>

<xs:element name="error">
<xs:complexType mixed="true">
<xs:attribute name="type" type="xs:string" use="required"/>
<xs:attribute name="message" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>

<xs:element name="skipped">
<xs:complexType mixed="true">
<xs:attribute name="type" type="xs:string" use="required"/>
<xs:attribute name="message" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="system-err" type="xs:string"/>
<xs:element name="system-out" type="xs:string"/>

<xs:element name="properties">
<xs:complexType>
<xs:sequence>
<xs:element ref="property" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="property">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="value" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>

<xs:element name="testcase">
<xs:complexType>
<xs:sequence>
<xs:element ref="skipped" minOccurs="0" maxOccurs="1"/>
<xs:element ref="error" minOccurs="0" maxOccurs="1"/>
<xs:element ref="failure" minOccurs="0" maxOccurs="1"/>
<xs:element ref="system-out" minOccurs="0" maxOccurs="1"/>
<xs:element ref="system-err" minOccurs="0" maxOccurs="1"/>
<xs:element ref="properties" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="time" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>

<xs:element name="testsuite">
<xs:complexType>
<xs:sequence>
<xs:element ref="testcase" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="tests" type="xs:string" use="required"/>
<xs:attribute name="failures" type="xs:string" use="required"/>
<xs:attribute name="errors" type="xs:string" use="required"/>
<xs:attribute name="disabled" type="xs:string" use="required"/>
<xs:attribute name="skipped" type="xs:string" use="required"/>
<xs:attribute name="time" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>

<xs:element name="testsuites">
<xs:complexType>
<xs:sequence>
<xs:element ref="testsuite" minOccurs="1" maxOccurs="1"/>
<xs:element ref="properties" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="time" type="xs:string" use="required"/>
<xs:attribute name="tests" type="xs:string" use="optional"/>
<xs:attribute name="failures" type="xs:string" use="optional"/>
<xs:attribute name="disabled" type="xs:string" use="optional"/>
<xs:attribute name="errors" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>
</xs:schema>
6 changes: 6 additions & 0 deletions tmt/steps/report/junit/templates/_base.xml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
{% if INCLUDE_OUTPUT_LOG and main_log %}
<system-out>{{ main_log | e }}</system-out>
{% endif %}

{% if (FLAVOR == 'polarion') and result.properties is defined %}
{% with properties=result.properties %}
{% include "includes/_properties.xml.j2" %}
{% endwith %}
{% endif %}
</testcase>
{% endfor %}
{% endblock %}
Expand Down
7 changes: 7 additions & 0 deletions tmt/steps/report/junit/templates/includes/_properties.xml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% if properties %}
<properties>
{% for property in properties %}
<property name="{{ property.name | e }}" value="{{ property.value | e }}"/>
{% endfor %}
</properties>
{% endif %}
10 changes: 10 additions & 0 deletions tmt/steps/report/junit/templates/polarion.xml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "_base.xml.j2" %}

{% block testsuites %}
{{ super() }}

{# Polarion XUnit must include the properties section in testsuites tag #}
{% with properties=TESTSUITES_PROPERTIES %}
{% include "includes/_properties.xml.j2" %}
{% endwith %}
{% endblock %}
Loading

0 comments on commit 96702c5

Please sign in to comment.