Skip to main content

Highly customizable pytest reporting plugin combining AI-optimized CTRF reports and rich test metrics

Project description

pytest-beacon

Highly customizable pytest reporting plugin. Generates CTRF 1.0.0 reports with rich test metadata — marks, parameters, Allure IDs, environment — and exports them to a local file and/or a remote HTTP service.

Features

  • CTRF 1.0.0 compliant JSON/YAML reports
  • Token-efficient by default (passed tests excluded from output, summary always accurate)
  • Rich metadata: marks, parametrized params, Allure IDs, environment name
  • HTTP export to a remote metrics service
  • Full pytest-xdist support (parallel execution)
  • Collection error tracking (import errors, syntax errors)
  • Configurable via CLI flags and environment variables

Installation

pip install pytest-beacon

Or with uv:

uv add pytest-beacon

Usage

# Basic — writes to beacon_reports/report-YYYYMMDD-HHMMSS.json
pytest --beacon

# Custom output file
pytest --beacon --beacon-file=results.json

# YAML format
pytest --beacon --beacon-format=yaml

# Send to remote service
pytest --beacon --beacon-url=http://localhost:8000/api/v1/metrics

# Include all test statuses in report (default excludes passed)
pytest --beacon --beacon-exclude-status=''

# Include stdout/stderr for passed tests
pytest --beacon --beacon-verbose

# Works with xdist
pytest --beacon -n auto

# Attach arbitrary metadata to the report
pytest --beacon --beacon-meta build=123 --beacon-meta branch=main --beacon-meta triggered_by=ci

CLI Options

Option Default Description
--beacon off Enable reporting
--beacon-file PATH beacon_reports/report-<ts>.json Output file. Bare filename → placed in beacon_reports/ with timestamp.
--beacon-url URL Full URL to POST the report to.
--beacon-format json|yaml json Report serialisation format
--beacon-verbose off Include captured stdout/stderr for passed tests
--beacon-exclude-status STATUSES passed Comma-separated statuses to omit from report output. Empty string includes all.
--beacon-meta KEY=VALUE Arbitrary metadata pair added to the report environment. Repeatable.

Environment Variables

All variables use the PYTEST_BEACON__ prefix.

Variable Description
PYTEST_BEACON__REPORT_FORMAT Default report format
PYTEST_BEACON__HTTP_TIMEOUT HTTP export timeout in seconds (default: 10.0)
PYTEST_BEACON__HTTP_MAX_RETRIES HTTP export retry attempts (default: 3)

Variables can also be set in a .env file at the project root.

Report Format

{
  "results": {
    "tool": { "name": "pytest", "version": "9.x" },
    "summary": {
      "tests": 12, "passed": 9, "failed": 2, "skipped": 1, "error": 0,
      "start": 1700000000000, "stop": 1700000005000
    },
    "tests": [
      {
        "name": "tests/test_api.py::test_login[admin]",
        "status": "failed",
        "duration": 142,
        "filePath": "tests/test_api.py",
        "line": 34,
        "message": "AssertionError: expected 200, got 401",
        "trace": "...",
        "marks": ["smoke", "auth"],
        "params": { "role": "admin" },
        "allureId": "TC-42"
      }
    ],
    "environment": { "pythonVersion": "3.12.0", "pytestVersion": "9.0.0", "xdistWorkers": 4, "build": "123", "branch": "main" },
    "extra": { "pluginName": "pytest-beacon", "pluginVersion": "0.1.0", "ctrf": "1.0.0" }
  }
}

Summary counters always reflect all tests regardless of --beacon-exclude-status.

Remote HTTP Export

When --beacon-url is set, a POST request with a JSON body is sent to the specified URL:

{
  "metrics": [
    {
      "test_nodeid": "tests/test_api.py::test_login[admin]",
      "test_name": "test_login[admin]",
      "test_result": "failed",
      "test_duration": 0.142,
      "test_marks": ["smoke", "auth"],
      "test_params": { "role": "admin" },
      "test_stacktrace": "...",
      "test_message": "AssertionError: expected 200, got 401",
      "test_allure_id": "TC-42"
    }
  ],
  "environment": {
    "pythonVersion": "3.12.0",
    "pytestVersion": "9.0.0",
    "xdistWorkers": 4,
    "build": "123",
    "branch": "main"
  }
}

Export errors are logged and never interrupt test execution.

Local Development

Install dependencies:

uv sync

Run tests:

uv run pytest tests/

Run a quick smoke test against your own test suite:

uv run pytest your_tests/ --beacon --beacon-exclude-status=

Requirements

  • Python 3.11+
  • pytest 9.0+

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

pytest_beacon-0.1.1.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

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

pytest_beacon-0.1.1-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file pytest_beacon-0.1.1.tar.gz.

File metadata

  • Download URL: pytest_beacon-0.1.1.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pytest_beacon-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4ed4dba3a5c638f87e5c927164fa8e24d9738320b5bc6690a427704f7afe10c5
MD5 99eb37fae7fcb8c3a1ae2fb594311a8d
BLAKE2b-256 80fbe00ae27688ee9d3fb19cad2f9ad3daa8cd2f19da1f1adde7a44606e2ea2e

See more details on using hashes here.

Provenance

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

Publisher: publish-to-pypi.yml on l0kifs/pytest-beacon

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

File details

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

File metadata

  • Download URL: pytest_beacon-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pytest_beacon-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f1da7c8259e12cb98b221fbb23762be79f0c7b6b986c3f9932ae154cf62e9177
MD5 8e5e94904a7f9a53f97d97b31b93411b
BLAKE2b-256 ccfbb9000adeca89a6c47217ce8a172009e8888d3e3f11e2ec563d44ff74270e

See more details on using hashes here.

Provenance

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

Publisher: publish-to-pypi.yml on l0kifs/pytest-beacon

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