python - How to add additional variable to pytest html report -


i using pytest html report plugin selenium tests. works great passing test.py --html==report.htmlin command line , generates great report.

i need implement additional string/variable each test case display. doesn't matter if it's pass or failed should show "ticket number". ticket id can return in each test scenario.

i add ticket number test name, ugly.

please advise what's best way it.

thank you.

you can insert custom html each test either adding html content "show details" section of each test, or customizing result table (e.g. add ticket column).

the first possibility simplest, can add following conftest.py

@pytest.mark.hookwrapper def pytest_runtest_makereport(item, call):     pytest_html = item.config.pluginmanager.getplugin('html')     outcome = yield     report = outcome.get_result()     = getattr(report, 'extra', [])     if report.when == 'call':         extra.append(pytest_html.extras.html('<p>some html</p>'))         report.extra = 

where can replace <p>some html</p> content.

the second solution be:

@pytest.mark.optionalhook def pytest_html_results_table_header(cells):     cells.insert(1, html.th('ticket'))   @pytest.mark.optionalhook def pytest_html_results_table_row(report, cells):     cells.insert(1, html.td(report.ticket))   @pytest.mark.hookwrapper def pytest_runtest_makereport(item, call):     outcome = yield     report = outcome.get_result()     report.ticket = some_function_that_gets_your_ticket_number() 

remember can access current test item object, might retrieving information need.


Comments