Skip to main content

Provides test results of unittest in JSON format, in order to be able to use the results programmatically.

Project description

CI Unit Test is a library which enables to retrieve the results of unit tests in JSON format. This may be used in custom Continuous Integration systems which need to process the results of unit tests.

The results can be saved as is to a NoSQL database, or can be returned as a Python object in order to be combined with other information before being saved.


The results in JSON format can be obtained by using JsonTestRunner:

suite = unittest.TestLoader().loadTestsFromTestCase(TestsDemo)
json = ciunittest.JsonTestRunner().run(suite, formatted=True)

Since the first line uses unittest, all unittest features are available, such as the auto-discovery of unit tests in a project directory:

suite = unittest.TestLoader().discover(targetPath)

To obtain the results as a Python object, use ObjectTestRunner:

suite = unittest.TestLoader().loadTestsFromTestCase(TestsDemo)
result = ciunittest.ObjectTestRunner().run(suite)
print('Done %d tests in %d ms.' %
      (len(result['results']), result['spentMilliseconds']))

To perform an action at the beginning of every test (independently of the runner being used,) do:

suite = unittest.TestLoader().loadTestsFromTestCase(TestsDemo)
runner = ciunittest.JsonTestRunner()
runner.on_start = lambda test: print(".", end="", flush=True)
result =

In the previous code sample, every time the runner is ready to start a new test, a dot is displayed in the terminal.

Similarly, one can execute arbitrary code at the end of every test. The test result, that is ciunittest.Success, ciunittest.Error or ciunittest.Failure, will be passed as a second parameter to the function.

runner.on_end = lambda test, result: print(result, flush=True)

The code is inspired by

If you have any question or remark, please contact me at Critics are also welcome, since I have used Python for only a few days, and probably get lots of things wrong.

Project details

Download files

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

Files for CIUnitTest, version 1.0.9
Filename, size File type Python version Upload date Hashes
Filename, size CIUnitTest-1.0.9-py3-none-any.whl (5.2 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size CIUnitTest-1.0.9.tar.gz (3.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page