Skip to main content

Export test results in an augmented JUnit format for usage with Xray ()

Project description

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 text in a property tag

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>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_junit_xray_xml-0.2.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_junit_xray_xml-0.2.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest_junit_xray_xml-0.2.0.tar.gz.

File metadata

  • Download URL: pytest_junit_xray_xml-0.2.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for pytest_junit_xray_xml-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7d5421cac0ec73280ab2fdb8351d37016158c3f828fb6ccd0566de70462a3816
MD5 3a3dbb5e7749b0177716a523a494f8ea
BLAKE2b-256 1f2a6d92f74336e61bab5c9ba676fa1efe4a86ac53b04afb7d3c4cba1d019129

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_junit_xray_xml-0.2.0.tar.gz:

Publisher: publish-to-pypi.yml on PascalVaudrevange/pytest-junit-xray-xml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_junit_xray_xml-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_junit_xray_xml-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71522b68c704deb6e314ae36fe85012aae92c69f77688de7e66d92a1fd0e2336
MD5 2a415172facfc070b1dc3ed8e047246d
BLAKE2b-256 9d5821a24e2a7ceb2e6b4f535dbe5efeadfa54c9576d095c657f4dff9fdcc4e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_junit_xray_xml-0.2.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on PascalVaudrevange/pytest-junit-xray-xml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page