Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Generate xUnit.xml files

Project Description


``xunitgen`` is a python module for the simple production of ``xunit``
or ``junit`` XML files for use in continuous integration. Such as with

It converts a stream of timed (start/finish/error) events and convert
them into a report.

It brings / need no dependencies besides an installation of ``Python 2``
or ``Python 3``.


Once you have added the directory surrounding ``xunitgen`` into your
``PYTHONPATH``, you can create simple test steps by using the

.. code:: python

import xunitgen

destination = xunitgen.XunitDestination('.')

with xunitgen.Recorder(destination, 'my-test-suite') as recorder:
with recorder.step('a-success') as step:

with recorder.step('a-failing-test') as step:
step.error('this step has failed')

with recorder.step('another-failing-test'):
raise Exception('I have failed too!')

Which will produce a file named my-test-suite.xml under the current

Lower level, event API

You can also use a lower level API (EventReceiver) if you need finer

.. code:: python

import xunitgen

receiver = xunitgen.EventReceiver()
receiver.begin_case('a-test', 0, 'foo')
receiver.failure('because', 'ExceptionFoo')
receiver.end_case('a-test', 9)

print xunitgen.tostring(receiver.results())

Example (event_trace module)

The xunitgen.event_trace module shows an example of using the lower
level API to convert a tracing format to xUnit files. This can be used
for instance by C programs/tests to produce test traces without having
to implement the xUnit format.



If you want to make code contributions to ``xunitgen`` here are the
steps to follow to get a working development environment:

Create a virtual environment and activate it

.. code:: example

$ virtualenv venv
$ . venv/bin/activate

Install development dependencies

.. code:: example

$ pip install -r dev_requirements.txt

With the virtual environment active, test your changes before

.. code:: example

$ nosetests -s tests

Additional Contributors

- Diez Roggisch <>
Release History

Release History

This version
History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
xunitgen-1.0.1.tar.gz (5.0 kB) Copy SHA256 Checksum SHA256 Source Dec 10, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting