I will summarize how to output docstring to the report of pytest-html as detailed information of the test function.
Add the following settings to conftest.py (created if it does not exist) directly under the tests directory. The title is inserted in the third column of the table header, and the information of the test function docstring is inserted in the third column of the table body.
conftest.py
import pytest
from py.xml import html
def pytest_html_results_table_header(cells):
cells.insert(2, html.th('Description'))
def pytest_html_results_table_row(report, cells):
cells.insert(2, html.td(report.description))
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
report.description = str(item.function.__doc__)
def test_one(self):
"""
This is test 1
"""
assert True
def test_two(self):
"""
This is test 2
"""
assert False
$ pytest --html=report.html
The docstring for each test function is displayed in the third column of the table.
Recommended Posts