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 or Bamboo. If you are ever working with test tool or test suite written in Python and want to take advantage of Jenkins’ or Bamboo’s 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. For Bamboo situation is the same.

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.9.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

junit_xml-1.9-py2.py3-none-any.whl (7.1 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: junit-xml-1.9.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for junit-xml-1.9.tar.gz
Algorithm Hash digest
SHA256 de16a051990d4e25a3982b2dd9e89d671067548718866416faec14d9de56db9f
MD5 a21d0456f5e44c7baedb029e174e8e42
BLAKE2b-256 98afbc988c914dd1ea2bc7540ecc6a0265c2b6faccc6d9cdb82f20e2094a8229

See more details on using hashes here.

File details

Details for the file junit_xml-1.9-py2.py3-none-any.whl.

File metadata

  • Download URL: junit_xml-1.9-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/2.7.16

File hashes

Hashes for junit_xml-1.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ec5ca1a55aefdd76d28fcc0b135251d156c7106fa979686a4b48d62b761b4732
MD5 dcb66da4f3905756ddb2432b0a7cdbdc
BLAKE2b-256 2a932d896b5fd3d79b4cadd8882c06650e66d003f465c9d12c488d92853dff78

See more details on using hashes here.

Supported by

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