Skip to main content

Generate JSON test reports

Project description

the json schema is highly in flux at the moment


See Build Status on Travis CI

pytest-json is a plugin for py.test that generates JSON reports for test results

This Pytest plugin was generated with Cookiecutter along with @hackebrot’s Cookiecutter-pytest-plugin template.


  • Python 2.7, 3.3, 3.4, 3.5
  • py.test 2.7 or newer


You can install “pytest-json” via pip from PyPI:

$ pip install pytest-json


$ py.test --json=report.json

or you can set the report path in an ini file:

json_report = report.json

The command-line option will override the ini file

There is an optional flag to normalize the generated report to jsonapi. This is intended for (easier) consumption by ember-data and others:

$ py.test --json=report.json --jsonapi

Adding to environment

You can modify request.config._json_environment in a fixture

@pytest.fixture(scope='session', autouse=True):
def extra_json_environment(request):
    request.config._json_environment.append(('herp', 'derp'))

Adding metadata per test stage

@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    if report.when == 'call':
        report.metadata = {
            'foo': 'bar'
    elif report.when == 'setup':
        report.metadata = {
            'hoof': 'doof'
    elif report.when == 'teardown':
        report.metadata = {
            'herp': 'derp'

Compatibility with pytest-html

To avoid issues with pytest-html, pytest-json uses request.config._json_environment instead of request.config._environment

Additionally, pytest-json ignores the extra field on reports.

Example json

A formatted example of the output can be found in example.json

The actual output is not formatted, but this was passed through jq for readability.


Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.


Distributed under the terms of the MIT license, “pytest-json” is free and open source software


If you encounter any problems, please file an issue along with a detailed description.

Download files

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

Files for pytest-json, version 0.3.1
Filename, size File type Python version Upload date Hashes
Filename, size pytest-json-0.3.1.tar.gz (5.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page