Skip to main content

Generate Pytest reports with templates

Project description

PyPI version

Generate Pytest reports from templates. You may use one of the available templates on PyPI (like the reference template pytest-reporter-html1), inherit them in your own template to tweak their content and appearence or make your own from scratch.

Anything text based can be generated like HTML, LaTeX, CSV et.c.

Installation

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

$ pip install pytest-reporter

Usage

Specify the template you want to use and the output path of the report:

$ pytest --template-dir=templates --template=report.html --report=report.html

Writing templates

This plugin does not come with built-in support for any template engines, it is up to each template to implement the rendering (or use another template plugin as base). A minimal template may just implement the pytest_reporter_render hook.

This is a very basic Jinja2 template implementation:

from jinja2 import Environment, FileSystemLoader, TemplateNotFound

def pytest_reporter_render(template_name, dirs, context):
    env = Environment(loader=FileSystemLoader(dirs))
    try:
        template = env.get_template(template_name)
    except TemplateNotFound:
        # Don't know about this name, may be provided by some other template
        return
    return template.render(context)

See pytest-reporter-html1 for a full reference implementation.

The template context

The standard context available for all templates include the following:

  • config: Config

  • session: Session

  • started: Unix timestamp when session started

  • ended: Unix timestamp when session was finished

  • warnings[]: List of warnings.WarningMessage

  • items: Dictionary of collected items with nodeid as keys

  • tests[]: List of each test run as dictionaries with the following keys:

    • item: Item

    • phases[]: List of each test phase (setup, call, teardown) as dictionaries with the following keys:

      • call (optional): CallInfo if available.

      • report: TestReport

      • sections: Same as report.sections but only the sections captured for this phase

      • log_records[]: List of logging.LogRecord recorded during the test phase

      • status: Status of this phase. Dictionary with the following keys:

        • category: Category of the status (e.g. "passed") or empty string

        • letter: Single letter version of status (e.g. "P") or empty string

        • word: Uppercase word version of status (e.g. "PASSED") or empty string

        • style: Dictionary with e.g. {"yellow": True} or empty dictionary

    • status: Status of whole test. Dictionary with the following keys:

      • category: Category of the test status (e.g. "passed")

      • letter: Single letter version of test status (e.g. "P")

      • word: Uppercase word version of test status (e.g. "PASSED")

      • style: Dictionary with e.g. {"yellow": True} or empty dictionary

The context may be extended or modified using the following methods:

  • config.template_context

  • The template_context fixture

  • The pytest_reporter_context() hook

Hooks

See hooks.py for a complete list of hooks available.

License

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

Issues

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

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-reporter-0.5.1.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_reporter-0.5.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest-reporter-0.5.1.tar.gz.

File metadata

  • Download URL: pytest-reporter-0.5.1.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for pytest-reporter-0.5.1.tar.gz
Algorithm Hash digest
SHA256 e3479c99152fc0ef2309e755001fec79740e82058a8f6484cfe1bfb82616ff3c
MD5 a5e2f41bfbabc0f3c39561447c983bb4
BLAKE2b-256 a73b81486231cb9246ef15cf8e7ae4c5af312f4d8d39d23443abf6e32a2d4f99

See more details on using hashes here.

File details

Details for the file pytest_reporter-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: pytest_reporter-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for pytest_reporter-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 10a8fe33d78f0f5c66482d65c8452d6dc297fbf87485942146b2b5a411353e8b
MD5 e3feb289da35d0fa39a08af8cf9d91ab
BLAKE2b-256 2cfb3ac3e7ea4074208742b137e1ce47cc2c9f94701db6384c934dfa27841c9b

See more details on using hashes here.

Supported by

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