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.
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| CIUnitTest-1.0.9.tar.gz | 3.2 kB | Without provenance | Details for CIUnitTest-1.0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| CIUnitTest-1.0.9-py3-none-any.whl | Python 3 | none | any | Details for CIUnitTest-1.0.9-py3-none-any.whl |
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 |
Security for CIUnitTest 1.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.