Skip to main content

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 with unittest.TestCase to automatically measure and report the execution time of each test method. It now uses time.monotonic() for more accurate duration measurements, helping in identifying slow tests and performance bottlenecks.
  • InventoryMixin: Designed for unittest.TestCase, this mixin now discovers all test_* methods within a class during setUpClass. In tearDownClass, 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: Extends unittest.TestResult to gather detailed information about the outcome of each test, including success, failure, errors, skips, and execution duration. It also uses time.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


Download files

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

Source Distribution

unittest_observability-0.1.1.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unittest_observability-0.1.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

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

Hashes for unittest_observability-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2649744691f8266282973807d75e33502cc0c63921657ee0f33c6aaa215762de
MD5 0465c5d28ce36eaf212500e6abad28b9
BLAKE2b-256 987a9bedc3f4e71173091271e829afba652e3fab82f9a3df29458d6a3d66c729

See more details on using hashes here.

Provenance

The following attestation bundles were made for unittest_observability-0.1.1.tar.gz:

Publisher: publish.yml on Eki23/unittest-observability

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file unittest_observability-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for unittest_observability-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 651c36e8df4ef4a6b75adf24240abea6dc3b328782e811c26809db59f3843047
MD5 31ee5b0a4cb07b599fc7192ec92c9457
BLAKE2b-256 68f080896af73f2ce1c38883c54d89beb9c55721a9812ec3abd31015f17d6988

See more details on using hashes here.

Provenance

The following attestation bundles were made for unittest_observability-0.1.1-py3-none-any.whl:

Publisher: publish.yml on Eki23/unittest-observability

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page