summaryrefslogtreecommitdiff
path: root/doc/en/usage.rst
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2018-01-29 15:42:55 -0200
committerGitHub <noreply@github.com>2018-01-29 15:42:55 -0200
commit49773b573f830d74ba5c3e1791ceced1b2614b25 (patch)
treeae97ab6d8c9102380e30b29de1af56eb3ec6008e /doc/en/usage.rst
parent32979def7d20ab94bbf665ec2d898eee5819d67c (diff)
parenta5e60b6a2d7f8044a08334cd4ca1a9873489528e (diff)
downloadpytest-49773b573f830d74ba5c3e1791ceced1b2614b25.tar.gz
Merge pull request #3132 from raphaelcastaneda/feature/add-record-xml-attribute
implement #3130 - add record_xml_attribute fixture
Diffstat (limited to 'doc/en/usage.rst')
-rw-r--r--doc/en/usage.rst60
1 files changed, 60 insertions, 0 deletions
diff --git a/doc/en/usage.rst b/doc/en/usage.rst
index 18830792b..417e50793 100644
--- a/doc/en/usage.rst
+++ b/doc/en/usage.rst
@@ -256,6 +256,66 @@ This will add an extra property ``example_key="1"`` to the generated
Also please note that using this feature will break any schema verification.
This might be a problem when used with some CI servers.
+record_xml_attribute
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. versionadded:: 3.4
+
+To add an additional xml attribute to a testcase element, you can use
+``record_xml_attribute`` fixture. This can also be used to override existing values:
+
+.. code-block:: python
+
+ def test_function(record_xml_attribute):
+ record_xml_attribute("assertions", "REQ-1234")
+ record_xml_attribute("classname", "custom_classname")
+ print('hello world')
+ assert True
+
+Unlike ``record_xml_property``, this will not add a new child element.
+Instead, this will add an attribute ``assertions="REQ-1234"`` inside the generated
+``testcase`` tag and override the default ``classname`` with ``"classname=custom_classname"``:
+
+.. code-block:: xml
+
+ <testcase classname="custom_classname" file="test_function.py" line="0" name="test_function" time="0.003" assertions="REQ-1234">
+ <system-out>
+ hello world
+ </system-out>
+ </testcase>
+
+.. warning::
+
+ ``record_xml_attribute`` is an experimental feature, and its interface might be replaced
+ by something more powerful and general in future versions. The
+ functionality per-se will be kept, however.
+
+ Using this over ``record_xml_property`` can help when using ci tools to parse the xml report.
+ However, some parsers are quite strict about the elements and attributes that are allowed.
+ Many tools use an xsd schema (like the example below) to validate incoming xml.
+ Make sure you are using attribute names that are allowed by your parser.
+
+ Below is the Scheme used by Jenkins to validate the XML report:
+
+ .. code-block:: xml
+
+ <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>
+
LogXML: add_global_property
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^