Skip to main content
Help us improve Python packaging – donate today!

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

Outreachy

Mozilla is participating in the Outreachy program helping people from groups underrepresented in free and open source software to get involved. For the round running May 23 to August 23, 2016, there is a project to work on several enhancements to pytest-html.

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

Release history Release notifications

History Node

1.17.0

History Node

1.16.1

History Node

1.16.0

History Node

1.15.2

History Node

1.15.1

History Node

1.15.0

History Node

1.14.2

History Node

1.14.1

History Node

1.14.0

History Node

1.13.0

History Node

1.12.0

History Node

1.11.1

History Node

1.11.0

History Node

1.10.1

History Node

1.10.1rc1

History Node

1.10.0

This version
History Node

1.9.0

History Node

1.8.1

History Node

1.8.0

History Node

1.7

History Node

1.6

History Node

1.5.1

History Node

1.5

History Node

1.4

History Node

1.3.2

History Node

1.3.1

History Node

1.3

History Node

1.2

History Node

1.1

History Node

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
pytest_html-1.9.0-py2.py3-none-any.whl (12.8 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Jul 4, 2016
pytest-html-1.9.0.tar.gz (10.5 kB) Copy SHA256 hash SHA256 Source None Jul 4, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page