Skip to main content

Emit Testhide-format (JUnit-extended) test reports from Python's unittest.

Project description

testhide-unittest-plugin

Emit Testhide-format (JUnit-extended) test reports straight from Python's built-in unittest — so the Testhide build agent parses your results correctly and the dashboard/AI features get full data, with zero manual XML.

It produces the exact same contract as testhide-pytest-plugin: fail_id, test_resolution, docstr/attachment/info/jira properties, <system-out>, suite metadata, and testhide_schema_version=1. See the canonical spec: Testhide Report Format v1.

Install

pip install testhide-unittest-plugin
# optional Jira enrichment:
pip install "testhide-unittest-plugin[jira]"

Usage

CLI (recommended) — a thin wrapper over unittest

# discover & run, writing the report:
python -m testhide_unittest discover -s tests -p "test_*.py" --report-xml junittests.xml

# run specific modules/classes:
python -m testhide_unittest tests.test_login --report-xml junittests.xml

Anything unittest accepts is passed through; Testhide options are consumed by the wrapper:

Option Meaning
--report-xml PATH output report (default junittests.xml)
--suite-name NAME <testsuite name="..."> (default unittest)
--quarantine-file PATH skip listed test ids (also TESTHIDE_QUARANTINE_FILE / .testhide_quarantine_file)
--meta KEY=VALUE add a suite <property> (repeatable; e.g. --meta build=1042 --meta branch=main)
--no-capture do not capture stdout/stderr into <system-out>
--jira-url / --jira-username / --jira-password optional Jira enrichment by fail_id

Exit code is 0 when all tests pass, 1 otherwise — drop it straight into CI.

Programmatic

import unittest
import testhide_unittest

runner = testhide_unittest.TesthideTestRunner(
    report_path="junittests.xml",
    metadata={"build": "1042", "branch": "main"},
)
unittest.main(testRunner=runner)

Enrich a test's report entry

import unittest
import testhide_unittest as th

class LoginTests(unittest.TestCase):
    def test_login(self):
        "User can log in with valid credentials."   # docstring -> docstr (automatic)
        th.attach("/tmp/screenshot.png")            # repeatable; images/logs/json
        th.set_info('{"env": "staging"}')           # free-form context
        th.set_jira("PROJ-123")                     # link a ticket
        ...

What it captures

  • Outcomes: pass / fail / error / skip / @expectedFailure (→ Known Issue) / unexpected pass.
  • fail_id = md5("module.class.function.ExceptionType(message)") — stable failure key for dedup + Jira linkage (identical to the pytest plugin).
  • file / line (for code-impact matching), test duration, docstring, attachments, info, jira, and captured stdout/stderr in <system-out>.
  • Suite metadata: hostname, ip, testhide_schema_version, plus your --meta properties.

Parallel / sharded runs

The writer is parallel-safe: each test is written to a temp chunk under .{report}_temp/, then atomically merged into the final report (file-locked). Counts are recomputed on merge.

Conformance

conformance/ vendors the canonical validator + golden fixture. CI runs the plugin against a sample suite and validates the output, guaranteeing the agent will parse it:

python conformance/validate_report.py junittests.xml

Publishing (maintainers)

Local publish (Windows):

copy .env.local.example .env.local   :: then edit .env.local and add PYPI_API_TOKEN
publish.bat

publish.bat loads .env.local (gitignored), runs the conformance tests, builds the sdist + wheel, and uploads to PyPI with twine.

.env.local:

PYPI_API_TOKEN=pypi-...      # https://pypi.org/manage/account/token/

CI publish (GitHub Actions): run the Publish to PyPI workflow (manual workflow_dispatch). Required repository secret:

  • PYPI_API_TOKEN — PyPI API token (Settings → Secrets and variables → Actions).

License

MIT.

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

testhide_unittest_plugin-0.1.3.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

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

testhide_unittest_plugin-0.1.3-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file testhide_unittest_plugin-0.1.3.tar.gz.

File metadata

  • Download URL: testhide_unittest_plugin-0.1.3.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for testhide_unittest_plugin-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c8544309a8ba85b261c49ebeb8873979af474dc2cdad6cd6fbd9273c295c2d24
MD5 b81c7995320bd2aab61659a350a1587a
BLAKE2b-256 edec6a9123ea909fd8293d230e1c974261df4bde0ab3a4c07e75c4d0c50d79ea

See more details on using hashes here.

File details

Details for the file testhide_unittest_plugin-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for testhide_unittest_plugin-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 61b13bbdb2ab9048094931039584645cb51d0f516686ea19d134b9c7795fdb84
MD5 9226ab4d9a470cf11aa53d13e4a1028b
BLAKE2b-256 b9f6c22e85d8cfe4444713b7ba5588790d65c5f88e9e626d425faf810dbcb7db

See more details on using hashes here.

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