Package: pytest-html-profiling
pytest-html-profiling is a plugin forpytestbased on the pytest-html plugin that generates a
HTML report for the test results along with profiling results and call graphs.RequirementsYou will need the following prerequisites in order to use pytest-html-profiling:Python 2.7, pytest-metadata, pygraphviz, gprof2dotInstallationTo install pytest-html-profiling:$pipinstallpytest-html-profilingThen run your tests with:$pytest--html=report.html--html-profiling--html-call-graphANSI codesNote that ANSI code support depends on theansi2htmlpackage. 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 reportsAppearanceCustom CSS (Cascasding Style Sheets) can be passed on the command line using
the--cssoption. 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.cssEnvironmentTheEnvironmentsection is provided by thepytest-metadata, plugin, and can be accessed
via thepytest_configurehook:defpytest_configure(config):config._metadata['foo']='bar'The generated table will be sorted alphabetically unless the metadata is acollections.OrderedDict.Additional summary informationYou can edit theSummarysection by using thepytest_html_results_summaryhook:importpytestfrompy.xmlimporthtmldefpytest_html_results_summary(prefix,summary,postfix):prefix.extend([html.p("foo: bar")])Extra contentYou 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:TypeExampleRaw HTMLextra.html('<div>AdditionalHTML</div>')JSONextra.json({'name':'pytest'})Plain textextra.text('Addsome simple Text')URLextra.url('http://www.example.com/')Imageextra.image(image,mime_type='image/gif',extension='gif')Imageextra.image('/path/to/file.png')Imageextra.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 formatExamplePNGextra.png(image)JPEGextra.jpg(image)SVGextra.svg(image)The following example adds the various types of extras using apytest_runtest_makereporthook, which can be implemented in a plugin or
conftest.py file:importpytest@pytest.hookimpl(hookwrapper=True)defpytest_runtest_makereport(item,call):pytest_html=item.config.pluginmanager.getplugin('html')outcome=yieldreport=outcome.get_result()extra=getattr(report,'extra',[])ifreport.when=='call':# always add url to reportextra.append(pytest_html.extras.url('http://www.example.com/'))xfail=hasattr(report,'wasxfail')if(report.skippedandxfail)or(report.failedandnotxfail):# only add additional html on failureextra.append(pytest_html.extras.html('<div>Additional HTML</div>'))report.extra=extraYou can also specify thenameargument for all types other thanhtmlwhich will change the title of the
created hyper link:extra.append(pytest_html.extras.text('some string',name='Different title'))Modifying the results tableYou can modify the columns by implementing custom hooks for the header and
rows. The following exampleconftest.pyadds a description column with
the test function docstring, adds a sortable time column, and removes the links
column:fromdatetimeimportdatetimefrompy.xmlimporthtmlimportpytestdefpytest_html_results_table_header(cells):cells.insert(2,html.th('Description'))cells.insert(1,html.th('Time',class_='sortable time',col='time'))cells.pop()defpytest_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)defpytest_runtest_makereport(item,call):outcome=yieldreport=outcome.get_result()report.description=str(item.function.__doc__)You can also remove results by implementing thepytest_html_results_table_rowhook and removing all cells. The
following example removes all passed results from the report:importpytestdefpytest_html_results_table_row(report,cells):ifreport.passed:delcells[:]The log output and additional HTML can be modified by implementing thepytest_html_results_htmlhook. The following example replaces all
additional HTML and log output with a notice that the log is empty:importpytestdefpytest_html_results_table_html(report,data):ifreport.passed:deldata[:]data.append(html.div('No log output captured.',class_='empty log'))Display optionsBy default, all rows in theResultstable will be expanded except those that havePassed.This behavior can be customized with a query parameter:?collapsed=Passed,XFailed,Skipped.ScreenshotsCall graphProfiling reportResourcesRelease NotesIssue TrackerCode