import pytest
pytest_plugins = ["pytest_html"]
def pytest_html_report_title(report):
"""modifying the title of html report"""
report.title = "Backend Testing Report"
def pytest_html_results_table_header(cells):
cells.insert(2, "
Detailed trip | ")
cells.insert(3, "Trip Duration | ")
cells.insert(4, "Target Duration | ")
cells[5] = "Execution time | " # rename the column containing execution times to avoid confusion
def pytest_html_results_table_row(report, cells):
trip_details = getattr(report, "trip_details", "N/A") # Default to "N/A" if no trip data
trip_duration = getattr(report, "trip_duration", "N/A") # Default to "N/A" if no trip data
target_duration = getattr(report, "target_duration", "N/A") # Default to "N/A" if no trip data
cells.insert(2, f"{trip_details} | ")
cells.insert(3, f"{trip_duration} | ")
cells.insert(4, f"{target_duration} | ")
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
report.description = str(item.function.__doc__)
# Attach trip_details if it exists
if hasattr(item, "trip_details"):
report.trip_details = " - ".join(item.trip_details) # Convert list to string
else:
report.trip_details = "N/A" # Default if trip_string is not set
# Attach trip_duration if it exists
if hasattr(item, "trip_duration"):
report.trip_duration = item.trip_duration + " min"
else:
report.trip_duration = "N/A" # Default if duration is not set
# Attach target_duration if it exists
if hasattr(item, "target_duration"):
report.target_duration = item.target_duration + " min"
else:
report.target_duration = "N/A" # Default if duration is not set