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.
Requirements
You will need the following prerequisites in order to use pytest-html:
Python 2.6, 2.7, 3.2, 3.3, 3.4, PyPy, or PyPy3
py.test 2.6 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._html.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:
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pytest_html-1.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11a681fd6e390a24f5843543a0a1d5d3c6ef6e20590328a6f06e55aa122335d9 |
|
MD5 | 8ebf304ff4956b189f1553374c7117d0 |
|
BLAKE2b-256 | c69653563295b8a15e0ad09f733c02662225938bedbf4a716e001762f06cce75 |