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.

License PyPI Travis Issues Requirements

Requirements

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

  • Python 2.6, 2.7, 3.3, 3.4, 3.5, PyPy, or PyPy3

  • py.test 2.7 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 change the Environment section of the report by modifying request.config._html.environment from a fixture:

@pytest.fixture(autouse=True)
def _environment(request):
    request.config._environment.append(('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:

import pytest
@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
    pytest_html = item.config.pluginmanager.getplugin('html')
    outcome = yield
    report = outcome.get_result()
    extra = getattr(report, 'extra', [])
    if report.when == 'call':
        # always add url to report
        extra.append(pytest_html.extras.url('http://www.example.com/'))
        xfail = hasattr(report, 'wasxfail')
        if (report.skipped and xfail) or (report.failed and not xfail):
            # only add additional html on failure
            extra.append(pytest_html.extras.html('<div>Additional HTML</div>'))
        report.extra = extra

Screenshots

Enhanced HTML 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.7.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

pytest_html-1.7-py2.py3-none-any.whl (11.7 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

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

File hashes

Hashes for pytest-html-1.7.tar.gz
Algorithm Hash digest
SHA256 2a278b39336e1f33e835b0c9d96bdbccc3234782c7362dcb87d9878674e599e5
MD5 500b6746419c9fbfbad597055e292705
BLAKE2b-256 bbbf76d2d464f8f611b8757bd1d69818e84e50ac45aa198a8bb2f70ed946d8cc

See more details on using hashes here.

File details

Details for the file pytest_html-1.7-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_html-1.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e63d9b918aacf7db65811e8cb02a29d31451eb94c4e31e5e558287aa402e0baa
MD5 dcdb98aba7431d155c75b24e43cca068
BLAKE2b-256 2098f5efb097a4ed14cead89cd25c7e07da272425d945729cd9c90a212ec4ca8

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