Pytest plugin for generating HTML reports with per-test profiling and optionally call graph visualizations. Based on pytest-html by Dave Hunt.
Project description
pytest-html-profiling is a plugin for pytest based on the pytest-html plugin that generates a HTML report for the test results along with profiling results and call graphs.
Requirements
You will need the following prerequisites in order to use pytest-html-profiling:
Python 2.7, pytest-metadata, pygraphviz, gprof2dot
Installation
To install pytest-html-profiling:
$ pip install pytest-html-profiling
Then run your tests with:
$ pytest --html=report.html --html-profiling --html-call-graph
ANSI codes
Note that ANSI code support depends on the ansi2html package. Due to the use of a less permissive license, this package is not included as a dependency. If you have this package installed, then ANSI codes will be converted to HTML in your report.
Enhancing reports
Appearance
Custom CSS (Cascasding Style Sheets) can be passed on the command line using
the --css
option. These will be applied in the order specified, and can
be used to change the appearance of the report.
$ pytest --html=report.html --css=highcontrast.css --css=accessible.css
Environment
The Environment section is provided by the pytest-metadata, plugin, and can be accessed
via the pytest_configure
hook:
def pytest_configure(config):
config._metadata['foo'] = 'bar'
The generated table will be sorted alphabetically unless the metadata is a
collections.OrderedDict
.
Additional summary information
You can edit the Summary section by using the pytest_html_results_summary
hook:
import pytest
from py.xml import html
def pytest_html_results_summary(prefix, summary, postfix):
prefix.extend([html.p("foo: bar")])
Extra content
You can add details to the HTML reports by creating an ‘extra’ list on the report object. Here are the types of extra content that can be added:
Type |
Example |
---|---|
Raw HTML |
extra.html('<div>Additional HTML</div>') |
extra.json({'name': 'pytest'}) |
|
Plain text |
extra.text('Add some simple Text') |
URL |
extra.url('http://www.example.com/') |
Image |
extra.image(image, mime_type='image/gif', extension='gif') |
Image |
extra.image('/path/to/file.png') |
Image |
extra.image('http://some_image.png') |
Note: When adding an image from file, the path can be either absolute or relative.
There are also convenient types for several image formats:
Image format |
Example |
---|---|
PNG |
extra.png(image) |
JPEG |
extra.jpg(image) |
SVG |
extra.svg(image) |
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.hookimpl(hookwrapper=True)
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
You can also specify the name
argument for all types other than html
which will change the title of the
created hyper link:
extra.append(pytest_html.extras.text('some string', name='Different title'))
Modifying the results table
You can modify the columns by implementing custom hooks for the header and
rows. The following example conftest.py
adds a description column with
the test function docstring, adds a sortable time column, and removes the links
column:
from datetime import datetime
from py.xml import html
import pytest
def pytest_html_results_table_header(cells):
cells.insert(2, html.th('Description'))
cells.insert(1, html.th('Time', class_='sortable time', col='time'))
cells.pop()
def pytest_html_results_table_row(report, cells):
cells.insert(2, html.td(report.description))
cells.insert(1, html.td(datetime.utcnow(), class_='col-time'))
cells.pop()
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
report.description = str(item.function.__doc__)
You can also remove results by implementing the
pytest_html_results_table_row
hook and removing all cells. The
following example removes all passed results from the report:
import pytest
def pytest_html_results_table_row(report, cells):
if report.passed:
del cells[:]
The log output and additional HTML can be modified by implementing the
pytest_html_results_html
hook. The following example replaces all
additional HTML and log output with a notice that the log is empty:
import pytest
def pytest_html_results_table_html(report, data):
if report.passed:
del data[:]
data.append(html.div('No log output captured.', class_='empty log'))
Display options
By default, all rows in the Results table will be expanded except those that have Passed
.
This behavior can be customized with a query parameter: ?collapsed=Passed,XFailed,Skipped
.
Screenshots
Call graph
Profiling 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
File details
Details for the file pytest-html-profiling-1.0.0.tar.gz
.
File metadata
- Download URL: pytest-html-profiling-1.0.0.tar.gz
- Upload date:
- Size: 483.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b8867b1d6a5b7e6b9d4a26f44e8e7e749adfd0e2c5014f4406706a12fe3d97e |
|
MD5 | d1ddd3f624980ceb1e134b36e6ba2c59 |
|
BLAKE2b-256 | 1d6fac5c3cee60ebcfa20a62637167c5cd271f9d2d555e7726a0f013be0db8ae |
File details
Details for the file pytest_html_profiling-1.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: pytest_html_profiling-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00f90063df79e9b21b96f68719376b46db80059b92a215ecaa7d4f60b281a689 |
|
MD5 | 7cfe16c038e4aab058c05f0ec134bfee |
|
BLAKE2b-256 | 01829daad63df298a618350604d64d1e315cad7c355591d13efb56044d978a02 |