Skip to content

Allow recording custom xml attributes #3130

@raphaelcastaneda

Description

@raphaelcastaneda

The experimental fixture record_xml_property inserts an additional <properties> element into the <testcase> element.

This violates typical junit xml validation, causing many parsers (e.g. Jenkins xunit plugin) to fail when processing pytest xml output that contains these extra properties.

While additional properties are very likely to break junit parsers, attributes may not.
For example, the junit spec does allow for an additional optional string attribute called assertions:

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

As a test author, I would like to be able to insert my own attributes on a testcase element.

Proposal:

  • Add an additional fixture called record_xml_attribute that allows a test author to add an attribute to the existing <testcase> element in the xml report.
  • This new fixture should take in two parameters: name and value
  • If a user specifies a name that overlaps with existing test case attributes, the user-specified values should overwrite the existing values.
  • User-specified attribute names should be xml-escaped

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: junitxmlrelated to the junitxml builtin plugintype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions