pytest-json-report

1.5.0 · active · verified Thu Apr 09

pytest-json-report is a pytest plugin that generates a comprehensive JSON report of your test results. It provides detailed information on test outcomes, collected items, and environment details, useful for integration with CI/CD systems or custom reporting tools. The current version is 1.5.0, with minor releases occurring every few months to address bugs and add features.

Warnings

Install

Quickstart

Create a `test_example.py` file with some tests, then run `pytest --json-report` from your terminal. This command will execute your tests and generate a `report.json` file in your current working directory containing the test results and a summary.

import pytest
import json
import os

def test_success():
    assert True

def test_failure():
    assert False

@pytest.mark.skip(reason="demonstrating skip")
def test_skipped():
    pass

def test_record_property(record_property):
    record_property("my_custom_key", "my_custom_value")
    assert True

# Run pytest and generate report.json
# os.system('pytest --json-report') would run it, but for a quickstart example, we'll demonstrate the command.
print("To run this example, save it as `test_example.py` and run:")
print("pytest --json-report")
print("Then inspect the generated `report.json` file.")

# Example of reading the report (would typically be in a separate script or CI/CD)
# if os.path.exists('report.json'):
#     with open('report.json', 'r') as f:
#         report_data = json.load(f)
#     print(json.dumps(report_data['summary'], indent=2))

view raw JSON →