Add a short description here
Project description
unittest-observability
This is a Python project for unittest observability.
Features
This library provides several mixins to enhance unittest with observability features:
TimingMixin: Integrates withunittest.TestCaseto automatically measure and report the execution time of each test method. It now usestime.monotonic()for more accurate duration measurements, helping in identifying slow tests and performance bottlenecks.InventoryMixin: Designed forunittest.TestCase, this mixin now discovers alltest_*methods within a class duringsetUpClass. IntearDownClass, it reports on the total number of tests discovered, how many actually ran, and identifies any tests that were skipped or not executed. This provides a comprehensive inventory and helps diagnose missing or skipped tests.ResultMixin: Extendsunittest.TestResultto gather detailed information about the outcome of each test, including success, failure, errors, skips, and execution duration. It also usestime.monotonic()for precise duration tracking and provides full tracebacks for issues. This provides a rich dataset for analysis and reporting.
Usage
TimingMixin and InventoryMixin
To use TimingMixin or InventoryMixin, simply inherit from them in your unittest.TestCase classes:
import unittest
from unittest_observability import TimingMixin, InventoryMixin
class MyTests(TimingMixin, InventoryMixin, unittest.TestCase):
def test_example(self):
# Your test code
self.assertTrue(True)
# To access inventory:
# inventory = MyTests.get_test_inventory()
TimingMixin will automatically print timing statistics to sys.stdout after the test class finishes. InventoryMixin will print its report in tearDownClass.
ResultMixin
ResultMixin extends unittest.TestResult and is designed to be used with a unittest.TextTestRunner (or similar test runner) by passing it as the resultclass argument. This allows it to collect detailed results from all tests run by the runner.
import unittest
from unittest_observability import ResultMixin
# Assuming you have a TestSuite or individual TestCases
suite = unittest.TestSuite()
# suite.addTest(...)
runner = unittest.TextTestRunner(resultclass=ResultMixin)
result = runner.run(suite)
# Access collected results
detailed_results = result.get_collected_results()
for test_info in detailed_results:
print(test_info)
Development and Publishing
This project uses GitHub Actions for continuous integration and publishing. A workflow is configured to build and publish the package to TestPyPI on pushes to the main branch or when a new tag (e.g., v1.0.0) is created. The CI pipeline now also includes coverage measurement to ensure code quality. Ensure you have a TEST_PYPI_API_TOKEN GitHub Secret configured for publishing.
For local development, you can run tests with coverage using the provided batch script:
run_tests_with_coverage.bat
Changelog
See CHANGELOG.md for a history of changes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unittest_observability-0.1.1.tar.gz.
File metadata
- Download URL: unittest_observability-0.1.1.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2649744691f8266282973807d75e33502cc0c63921657ee0f33c6aaa215762de
|
|
| MD5 |
0465c5d28ce36eaf212500e6abad28b9
|
|
| BLAKE2b-256 |
987a9bedc3f4e71173091271e829afba652e3fab82f9a3df29458d6a3d66c729
|
Provenance
The following attestation bundles were made for unittest_observability-0.1.1.tar.gz:
Publisher:
publish.yml on Eki23/unittest-observability
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unittest_observability-0.1.1.tar.gz -
Subject digest:
2649744691f8266282973807d75e33502cc0c63921657ee0f33c6aaa215762de - Sigstore transparency entry: 2045958580
- Sigstore integration time:
-
Permalink:
Eki23/unittest-observability@df623a859571b7b1e31a0b3f69d22abe871c7c79 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Eki23
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@df623a859571b7b1e31a0b3f69d22abe871c7c79 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file unittest_observability-0.1.1-py3-none-any.whl.
File metadata
- Download URL: unittest_observability-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
651c36e8df4ef4a6b75adf24240abea6dc3b328782e811c26809db59f3843047
|
|
| MD5 |
31ee5b0a4cb07b599fc7192ec92c9457
|
|
| BLAKE2b-256 |
68f080896af73f2ce1c38883c54d89beb9c55721a9812ec3abd31015f17d6988
|
Provenance
The following attestation bundles were made for unittest_observability-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on Eki23/unittest-observability
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unittest_observability-0.1.1-py3-none-any.whl -
Subject digest:
651c36e8df4ef4a6b75adf24240abea6dc3b328782e811c26809db59f3843047 - Sigstore transparency entry: 2045958971
- Sigstore integration time:
-
Permalink:
Eki23/unittest-observability@df623a859571b7b1e31a0b3f69d22abe871c7c79 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Eki23
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@df623a859571b7b1e31a0b3f69d22abe871c7c79 -
Trigger Event:
workflow_dispatch
-
Statement type: