Skip to main content

Pytest plugin to generate json report in CTRF (Common Test Report Format)

Project description

CTRF for pytest

Pytest implementation of Common Test Report Format (CTRF) for test results.
Test report will be generated in JSON format.
Test report can be used to prettify the report in GitHub Actions with github-actions-ctrf.
Do not worry if report in GitHub does not appear immediately. It takes some time to process the report.

Features

  • Generates JSON report
  • Tested to work correctly with and without pytest-xdist
  • Tested to get browser name from pytest-playwright
  • Parametrized tests are supported and reported as 1 test with multiple retries

Installation

pip install pytest-json-ctrf

Usage

generate report.json file in the root directory of the project. File path is mandatory

pytest --ctrf report.json

Environment Variables may be used to specify the required Environment Object fields when using the CTRF slack-test-reporter.

CTRF_BUILD_NAME="Pytest JSON CTRF Report"
CTRF_BUILD_NUMBER="000"
CTRF_BUILD_URL="https://ctrf.io]"

JSON example

More info here: https://ctrf.io/docs/schema/examples

{
  "reportFormat": "CTRF",
  "specVersion": "0.0.0",
  "generatedBy": "pytest",  
  "results": {
    "tool": {
      "name": "jest"
    },
    "summary": {
      "tests": 3,
      "passed": 1,
      "failed": 1,
      "pending": 0,
      "skipped": 1,
      "other": 0,
      "start": 1706644023,
      "stop": 1706644043
    },
    "environment": {
        "buildName": "Pytest JSON CTRF Report",
        "buildNumber": "000",
        "buildUrl": "https://ctrf.io"
    },
    "tests": [
      {
        "name": "User should be able to login",
        "status": "passed",
        "duration": 1200
      },
      {
        "name": "User profile information should be correct",
        "status": "failed",
        "duration": 800
      },
      {
        "name": "User should be able to logout",
        "status": "skipped",
        "duration": 0
      }
    ]
  }
}

Report Example

Example Image

Technical details

For future me and others who are interested in the technical details of the implementation.
The main idea is to handle xdist plugin because without it collecting report is quite straightforward.
By the example of putest-json-report plugin, I have learned that different plugins can be registered for the controller and workers node.
The pytest_runtest_logreport hook in the controller node is used to collect the test results from all the nodes so other nodes can just add some details to the TestReport object.

Credits

Changelog

  • 0.5.1 - added mandatory root object fields: reportFormat, specVersion, generatedBy
  • 0.5.0 - Changed logic of handling parametrized tests. Previously they were marked as retries, now they are reported as separate tests
  • 0.4.1 - Introduced backward compatibility with python 3.8, fixed issues with the time formats

Roadmap

  • Add screenshots handling
  • Add hooks for the report extension

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_json_ctrf-0.5.2.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

pytest_json_ctrf-0.5.2-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest_json_ctrf-0.5.2.tar.gz.

File metadata

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

File hashes

Hashes for pytest_json_ctrf-0.5.2.tar.gz
Algorithm Hash digest
SHA256 cd129ab2bc378a716a6a62830973a894fc486c5a6132f868b8705ede5f53bb3a
MD5 c9fc00a1d2c52ca9cb73d21bb02be8d8
BLAKE2b-256 a9fd8bc3a861fe3c57f6c730688c1cde8c2c189cbf7c5a30767c76dc92ea4cf0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_json_ctrf-0.5.2.tar.gz:

Publisher: deploy.yml on qamania/pytest-common-test-report-json

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_json_ctrf-0.5.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_json_ctrf-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a427205bf624a1d85ae807aa20f30ddd194699a9621a13178f766179658d9607
MD5 07dc2f77fa19f2fa2709eff2de9dccaf
BLAKE2b-256 2ed02e530f636cbfb33a98c124836f76a7d856a55bf93a6e832f78ee0c9adadb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_json_ctrf-0.5.2-py3-none-any.whl:

Publisher: deploy.yml on qamania/pytest-common-test-report-json

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