Skip to main content

A plugin to generate customizable jinja-based HTML reports in pytest

Project description

pytest-jinja is a plugin to generate customizable jinja-based HTML reports in pytest. It’s based on pytest-html, but changes its inner working completely by separating the results data collection and the report generation, allowing easy developent of custom HTML reports that can include any javascript or css.

License Python versions See Build Status on Azure Pipelines Issues

Requirements

You will need the following prerequisites in order to use pytest-html:

  • Python 3.6

Installation

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

$ pip install pytest-jinja

Usage

  • if no template is specified a default template is used. The default template looks almost identical to pytest-html:

    $ pytest testcase --html-report=test_report.html
  • or you can pass your own template, pytest-jinja will render your template passing in the report data as jinja variables:

    $ pytest testcase --html-report=test_report.html --html-template=my_template.html

Creating a custom template

You can create your own template by simply creating any html page. The report data is “passed” to the page as a single object called report. The attributes of this object contain all the necessary report data.

Template Example

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test Report - {{ report.time_report_generation }}</title>
</head>
<body>
<h1>Test Report - {{ report.time_report_generation }} </h1>

<h2>Environment</h2>
<table id="environment">
    {% for name,value in report.environment.items() %}
    <tr>
        <td>{{ name }}</td>
        <td>{{ value }}</td>
    </tr>
    {% endfor %}
</table>

<h2>Summary</h2>
<p>{{ report.tests_count }} tests ran in {{ report.duration | round(2)}} seconds. </p>

<h2>Results</h2>
<table>
    {% for r in report.results %}
    <tr>
        <td>{{ r.test_id }}</td>
        <td>{{ r.outcome }}</td>
        <td><strong>{{ r.time|round(5) }}s</strong></td>
    </tr>
    {% endfor %}
</table>

</body>
</html>

Available Report Data

report.tests_count : the total number of tests executed (int)

report.errors : the number of errors (int)

report.failed : the number of failed tests (int)

report.passed : the number of passed tests (int)

report.skipped : the number of skipped tests (int)

report.xfailed : the number of expected failures (int)

report.xpassed: the number of unexpected passes (int)

report.rerun: the number of reruns (int)

report.duration : the test session duration in seconds (float)

report.time_report_generation : date and time of report generation (str)

report.environment: metadata on tests execution (dict)

report.results: the test results data (Object with attributes test_id, time, outcome, stacktrace, config)

report.report_path: report path passed via command line (pathlib.Path)

report.template_path: template path passed via command line (pathlib.Path)

Contributing

Contributions are very welcome. Tests can be run with tox.

License

Distributed under Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. “pytest-jinja” is free and open source software

Issues

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

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

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-jinja-0.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

pytest_jinja-0.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest-jinja-0.1.0.tar.gz.

File metadata

  • Download URL: pytest-jinja-0.1.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.4 Linux/5.15.0-46-generic

File hashes

Hashes for pytest-jinja-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2c4c9241aa1c785b6a6a388db6d1cba2cb850fd3da5bef4d61cbbc2b5f8d5bde
MD5 3faafb9053f38a543cf47bc30494be07
BLAKE2b-256 13ac4e6c5b9a4402db7c43184cfdae9b3fac7610cd1f16447f66d44ce2c7a2eb

See more details on using hashes here.

File details

Details for the file pytest_jinja-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_jinja-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.4 Linux/5.15.0-46-generic

File hashes

Hashes for pytest_jinja-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4b586f1aad77c885866f3ec85ce705f8a98ce39acb488002af2d073ef851c7d
MD5 1318806420d0d49bd78030e91527406c
BLAKE2b-256 6be8c8ca0e4cbee0f44474315dea12c3620c804304c2f12140a874c5b7afbbb2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page