Skip to main content

Creates JUnit XML test result documents that can be read by tools such as Jenkins

Project description

https://travis-ci.org/kyrus/python-junit-xml.png?branch=master

About

A Python module for creating JUnit XML test result documents that can be read by tools such as Jenkins. If you are ever working with test tool or test suite written in Python and want to take advantage of Jenkins’ pretty graphs and test reporting capabilities, this module will let you generate the XML test reports.

As there is no definitive Jenkins JUnit XSD that I could find, the XML documents created by this module support a schema based on Google searches and the Jenkins JUnit XML reader source code. File a bug if something doesn’t work like you expect it to.

Installation

Install using pip or easy_install:

pip install junit-xml
or
easy_install junit-xml

You can also clone the Git repository from Github and install it manually:

git clone https://github.com/kyrus/python-junit-xml.git
python setup.py install

Using

Create a test suite, add a test case, and print it to the screen:

from junit_xml import TestSuite, TestCase

test_cases = [TestCase('Test1', 'some.class.name', 123.345, 'I am stdout!', 'I am stderr!')]
ts = TestSuite("my test suite", test_cases)
# pretty printing is on by default but can be disabled using prettyprint=False
print(TestSuite.to_xml_string([ts]))

Produces the following output

<?xml version="1.0" ?>
<testsuites>
    <testsuite errors="0" failures="0" name="my test suite" tests="1">
        <testcase classname="some.class.name" name="Test1" time="123.345000">
            <system-out>
                I am stdout!
            </system-out>
            <system-err>
                I am stderr!
            </system-err>
        </testcase>
    </testsuite>
</testsuites>

Writing XML to a file:

# you can also write the XML to a file and not pretty print it
with open('output.xml', 'w') as f:
    TestSuite.to_file(f, [ts], prettyprint=False)

See the docs and unit tests for more examples.

NOTE: Unicode characters identified as “illegal or discouraged” are automatically stripped from the XML string or file.

Running the tests

# activate your virtualenv
pip install tox
tox

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

junit-xml-1.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

junit-xml-1.1.macosx-10.8-intel.tar.gz (6.6 kB view details)

Uploaded Source

File details

Details for the file junit-xml-1.1.tar.gz.

File metadata

  • Download URL: junit-xml-1.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for junit-xml-1.1.tar.gz
Algorithm Hash digest
SHA256 f34737157fb74e3771c97331f11f188d7e099e2d64fb1e6419a17dc380e58684
MD5 86158819d747db99d1d2d6a73ab90845
BLAKE2b-256 2620be6b4b8da661a69acae73adb4a2da07a118d0800115b3cbc4b15f19eb5ee

See more details on using hashes here.

File details

Details for the file junit-xml-1.1.macosx-10.8-intel.tar.gz.

File metadata

File hashes

Hashes for junit-xml-1.1.macosx-10.8-intel.tar.gz
Algorithm Hash digest
SHA256 3bd94fc2f38e372ea3c3d2c17e48a073bb2a69e2582df06d885a80fb974de777
MD5 f1434f3e1ff51028a00675e7ceea9b0f
BLAKE2b-256 d292992042d570c7cb162958f60b35001e00348d3075e92f7d66694837d7bd78

See more details on using hashes here.

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