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.

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.

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

CIUnitTest-1.0.9.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

CIUnitTest-1.0.9-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file CIUnitTest-1.0.9.tar.gz.

File metadata

  • Download URL: CIUnitTest-1.0.9.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for CIUnitTest-1.0.9.tar.gz
Algorithm Hash digest
SHA256 e5138430654e38ecd39f3362e6e4247a001c61ce7c6630a4d4c7ee9a0cb9d55b
MD5 9ea637770f2e72587e8ea9de43b939f2
BLAKE2b-256 76d831359b5284ab77a369b5c4f6b7614b5820bce4b378b215fab785e824e2fd

See more details on using hashes here.

File details

Details for the file CIUnitTest-1.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for CIUnitTest-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 22f9012ea85758e848192863012e249de16eee2f75371ef510a6ce6272e6501c
MD5 f29d76d0ecf6bbc66521bd95740a0722
BLAKE2b-256 4c1576f83e663dfce9e3f87b239d52a341c01c531668eee7c30d86be415e34e1

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