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

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(ts.to_xml_string())

Produces the following output

<?xml version="1.0" ?>
<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>

Writing XML to a file:

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

See the docs and unit tests for more examples.

Running the tests

python tests.py

Project details


Download files

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

Source Distributions

junit-xml-1.0.zip (9.8 kB view details)

Uploaded Source

junit-xml-1.0.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file junit-xml-1.0.zip.

File metadata

  • Download URL: junit-xml-1.0.zip
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for junit-xml-1.0.zip
Algorithm Hash digest
SHA256 0ef12353eb71afdc979f595b0bbf3e1611aaabe61d8961113c7d4764b6c1c3da
MD5 11a609f1174cd05d951ed4a0cf4dd24a
BLAKE2b-256 515e845fb85e4152e1950e08ca29ab4f10085504dc597f6fa4a57623a485442b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for junit-xml-1.0.tar.gz
Algorithm Hash digest
SHA256 86570ff0af0c7c6ca3f18691a34be41ed47aea6dc84d832559471e9cf7c8b0f3
MD5 b4b6f2d9a247bd50bd0246ce014ef8f3
BLAKE2b-256 6334995c6f062e813f52ba42e82f3d21a8f25fbdf375cede1bfbf36112636ca0

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