Skip to content

Plugin for generating HTML reports for py.test results

License

Notifications You must be signed in to change notification settings

dhoomakethu/pytest-html

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pytest-html

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

def pytest_runtest_makereport(__multicall__, item):
    pytest_html = item.config.pluginmanager.getplugin('html')
    report = __multicall__.execute()
    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(html.div('Additional HTML')))
        report.extra = extra
    return report

Resources

About

Plugin for generating HTML reports for py.test results

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 71.4%
  • JavaScript 19.1%
  • CSS 9.5%