pytest-junit-xray-xml
This plugin for pytest exports test results in an extended JUnit format for consumption by the Xray plugin for Jira.
This plugin aims to also be a drop-in replacement for pytest's built-in JUnit support, so all non-Xray-related functionality will (hopefully soon) be supported.
Rationale
The JUnit support in pytest does not allow for the following features:
- it is not possible to generate
<item>elements as subnodes of a<property>tag (needed for storing test evidence) - it is not possible to store
textin apropertytag
Installation
This package is available on pypi.org
python -m pip install pytest-junit-xray-xml
Usage
[!NOTE] You need to explicitly import all fixtures that you want to use, e.g.
from pytest_junit_xray_xml import record_test_key
To export the results as Xray-compatible JUnit, please start pytest with the parameter --junit-xray-xml <filename.xml>, e.g.
python -m pytest tests/examples.py --junit-xray-xml xray.xml
(All examples are available in tests/examples.py and can be run via the command above)
The following fixtures are supported.
record_test_key
stores the test key in a property named test_key. Xray will attach the test results to the test case identified by this key.
[!ALERT] Only a single test key is supported at the moment
example
def test_record_test_key(record_test_key):
record_test_key("JIRA-1234")
assert True
output
<property name="test_key" value="JIRA-1234" />
record_test_id
stores the test ID in a property named test_id. Xray will attach the test results to the test case identified by this key.
[!ALERT] Only a single test key is supported at the moment
example
def test_record_test_key(record_test_key):
record_test_key("JIRA-1234")
assert True
output
<property name="test_key" value="JIRA-1234" />
record_test_description
stores the (potentially multi-line) test description as the text of a property named test_description. This cannot be accomplished with base pytest fixtures.
example
def test_record_multiple_descriptions(record_test_description):
record_test_description("This is my test description line 1")
record_test_description("and line 2.")
assert True
output
<property name="test_description">This is my test description line 1
and line 2.</property>
record_test_evidence
stores the test evidence with base64 encoding inside the XML. Xray will attach this file to the corresponding Jira ticket.
Multiple files with evidence can be stored for a single test case (not shown in the example below).
example
def test_store_test_evidence(record_test_evidence):
with record_test_evidence("file1.txt", "w", encoding="UTF-8") as f:
f.write("My file content is text")
assert True
output
<property name="testrun_evidence">
<item name="file1.txt">TXkgZmlsZSBjb250ZW50IGlzIHRleHQ=</item>
</property>
example
def test_store_test_evidence_xml(record_test_evidence):
xml_content = ElementTree(Element("my_root", my_attribute="1"))
with record_test_evidence("file1.xml", "wb") as f:
xml_content.write(f)
assert True
output
<property name="testrun_evidence">
<item name="file1.xml">PG15X3Jvb3QgbXlfYXR0cmlidXRlPSIxIiAvPg==</item>
</property>
Metadata
Release files for pytest-junit-xray-xml 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_junit_xray_xml-0.2.0.tar.gz | 10.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_junit_xray_xml-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.1 kB
Release files / pytest_junit_xray_xml-0.2.0.tar.gz
| Download URL | pytest_junit_xray_xml-0.2.0.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7d5421cac0ec73280ab2fdb8351d37016158c3f828fb6ccd0566de70462a3816
|
|
BLAKE2b-256 checksum How to use checksums |
1f2a6d92f74336e61bab5c9ba676fa1efe4a86ac53b04afb7d3c4cba1d019129
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 1, 2025.
Transparency logRelease files / pytest_junit_xray_xml-0.2.0-py3-none-any.whl
| Download URL | pytest_junit_xray_xml-0.2.0-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
71522b68c704deb6e314ae36fe85012aae92c69f77688de7e66d92a1fd0e2336
|
|
BLAKE2b-256 checksum How to use checksums |
9d5821a24e2a7ceb2e6b4f535dbe5efeadfa54c9576d095c657f4dff9fdcc4e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 1, 2025.
Transparency log