How to add additional variable to pytest html report
You can insert custom html for each test by either adding html content to the "show details" section of each test, or customizing the result table (e.g. add a ticket column).
The first possibility is the simplest, you can just add the following to your conftest.py
@pytest.mark.hookwrapperdef 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': extra.append(pytest_html.extras.html('<p>some html</p>')) report.extra = extra
Where you can replace <p>some html</p>
with your content.
The second solution would be:
@pytest.mark.optionalhookdef pytest_html_results_table_header(cells): cells.insert(1, html.th('Ticket'))@pytest.mark.optionalhookdef pytest_html_results_table_row(report, cells): cells.insert(1, html.td(report.ticket))@pytest.mark.hookwrapperdef pytest_runtest_makereport(item, call): outcome = yield report = outcome.get_result() report.ticket = some_function_that_gets_your_ticket_number()
Remember that you can always access the current test with the item object, this might help retrieving the information you need.