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.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
Creating a self-contained report
In order to respect the Content Security Policy (CSP), several assets such as CSS and images are stored separately by default. You can alternatively create a self-contained report, which can be more convenient when sharing your results. This can be done in the following way:
$ py.test --html=report.html --self-contained-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
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.10.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 808ddd5e9346606300eeb38a7c9ee917ca3df1c51075d02449e9cf5956ae8efb |
|
MD5 | 5d30341d80d4d9cd8d7f53c071df2990 |
|
BLAKE2b-256 | b2f9fed1559b0b6a931284e58d9e98cd1b43786aef4c4892d7be66f079d06bc4 |