Skip to main content

pytest-jinja

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 Issues

This version is a fork from [g-bon’s pytest-jinja](https://github.com/g-bon/pytest-jinja).


Requirements

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

  • Python 3.10

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 --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 --report=test_report.html --template=my_template.html

Creating a custom template

You can create your own template by simply creating any template. 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>

Another Template Example

{{ report | json }}

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.

Metadata

Release files for pytest-jinja 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-jinja 0.1.3
File Size Uploaded
pytest-jinja-0.1.3.tar.gz 11.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-jinja 0.1.3
File Interpreter ABI Platform
pytest_jinja-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 23.6 kB

Release files / pytest-jinja-0.1.3.tar.gz

Download URL pytest-jinja-0.1.3.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a88ebadf724ec00cb3f8aba52a775f32714655a83e8425b317f1e8a645aeb8bf
BLAKE2b-256 checksum
How to use checksums
0698ce113349113ee64d48ba02b11ee783ad1cfd600423c613a69ce40f9bb880
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release files / pytest_jinja-0.1.3-py3-none-any.whl

Download URL pytest_jinja-0.1.3-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
911aeed2eaa41b6824a74ddafc5823fb564ca64b34450f311adef47435174755
BLAKE2b-256 checksum
How to use checksums
20ac3341c0113ac2e775ebec691c1c36e77e3528138aefc947b508ef105293bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page