Metadata-Version: 2.1
Name: pytest-jinja
Version: 0.1.0
Summary: A plugin to generate customizable jinja-based HTML reports in pytest
Home-page: https://github.com/g-bon/pytest-jinja
License: GPL-2.0
Keywords: py.test,pytest,html,testing,report
Author: Gabriele Bonetti
Author-email: gabriele.bonetti@gmail.com
Requires-Python: >=3.6,<4.0
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU General Public License v2 (GPLv2)
Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Utilities
Requires-Dist: jinja2
Requires-Dist: pytest (>=5.2.2,<6.0.0)
Requires-Dist: pytest-metadata
Project-URL: Repository, https://github.com/g-bon/pytest-jinja
Description-Content-Type: text/x-rst

===================
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.


.. image:: https://img.shields.io/badge/license-MPL%202.0-blue.svg
   :target: https://github.com/g-bon/pytest-jinja/blob/master/LICENSE
   :alt: License

.. image:: https://img.shields.io/pypi/pyversions/pytest-jinja.svg
    :target: https://pypi.org/project/pytest-jinja
    :alt: Python versions

.. image:: https://dev.azure.com/gbon/pytest-jinja/_apis/build/status/g-bon.pytest-jinja?branchName=master
    :target: https://dev.azure.com/gbon/pytest-jinja/_build/latest?definitionId=1&branchName=master
    :alt: See Build Status on Azure Pipelines

.. image:: https://img.shields.io/github/issues-raw/g-bon/pytest-jinja.svg
    :target: https://github.com/g-bon/pytest-jinja/issues
    :alt: 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
----------------
.. code-block:: django

    <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.


.. _`Cookiecutter`: https://github.com/audreyr/cookiecutter
.. _`@hackebrot`: https://github.com/hackebrot
.. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin
.. _`file an issue`: https://github.com/g-bon/pytest-jinja/issues
.. _`pytest`: https://github.com/pytest-dev/pytest
.. _`tox`: https://tox.readthedocs.io/en/latest/
.. _`pip`: https://pypi.org/project/pip/
.. _`PyPI`: https://pypi.org/project

