Skip to main content

pytest plugin for generating HTML reports

Project description

pytest-html is a plugin for py.test that generates a HTML report for the test results.

https://travis-ci.org/davehunt/pytest-html.svg

Requirements

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

  • Python 2.6, 2.7, 3.2, 3.3, 3.4 or PyPy

  • py.test 2.3 or newer

Installation

To install pytest-html:

$ pip install pytest-html

Then run your tests with:

$ py.test --html=report.html

Enhancing reports

You can add an Environment section to the report by implementing the pytest_html_environment hook and returning a dict representing the test environment. For example:

def pytest_html_environment(config):
    return {'foo': 'bar'}

You can add details to the HTML reports by creating an ‘extra’ list on the report object. The following example adds the various types of extras using a pytest_runtest_makereport hook, which can be implemented in a plugin or conftest.py file:

from py.xml import html
from html import extras

def pytest_runtest_makereport(__multicall__, item):
    report = __multicall__.execute()
    extra = getattr(report, 'extra', [])
    if report.when == 'call':
        xfail = hasattr(report, 'wasxfail')
        if (report.skipped and xfail) or (report.failed and not xfail):
            url = TestSetup.selenium.current_url
            report.extra.append(extras.url(url))
            screenshot = TestSetup.selenium.get_screenshot_as_base64()
            report.extra.append(extras.image(screenshot, 'Screenshot'))
            html = TestSetup.selenium.page_source.encode('utf-8')
            report.extra.append(extra.text(html, 'HTML'))
            report.extra.append(extra.html(html.div('Additional HTML')))
        report.extra = extra
    return report

Resources

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-html-1.1.tar.gz (7.1 kB view details)

Uploaded Source

File details

Details for the file pytest-html-1.1.tar.gz.

File metadata

  • Download URL: pytest-html-1.1.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pytest-html-1.1.tar.gz
Algorithm Hash digest
SHA256 65e6f3ade1cd6de4992af3b461e4788babb2ba02ec90637ef700f08b6e26f2ec
MD5 8ca645b531c1462726eebcb1cf0e0516
BLAKE2b-256 7eb6adfd8f399c2456bf4570cbe186e484f2980d8e3fda158c1cace37d875947

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