Skip to main content

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.

Usage

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

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

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 = runner.run(suite)
...

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 http://pythonhosted.org/gchecky/unittest-pysrc.html

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

Release files for CIUnitTest 1.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for CIUnitTest 1.0.9
File Size Uploaded
CIUnitTest-1.0.9.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for CIUnitTest 1.0.9
File Interpreter ABI Platform
CIUnitTest-1.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 8.5 kB

Release files / CIUnitTest-1.0.9.tar.gz

Download URL CIUnitTest-1.0.9.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e5138430654e38ecd39f3362e6e4247a001c61ce7c6630a4d4c7ee9a0cb9d55b
BLAKE2b-256 checksum
How to use checksums
76d831359b5284ab77a369b5c4f6b7614b5820bce4b378b215fab785e824e2fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / CIUnitTest-1.0.9-py3-none-any.whl

Download URL CIUnitTest-1.0.9-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
22f9012ea85758e848192863012e249de16eee2f75371ef510a6ce6272e6501c
BLAKE2b-256 checksum
How to use checksums
4c1576f83e663dfce9e3f87b239d52a341c01c531668eee7c30d86be415e34e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.9 This release

2 release files

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page