pytest-html icon indicating copy to clipboard operation
pytest-html copied to clipboard

Update documentation to contain start time of test instead of end time

Open sturmf opened this issue 2 years ago • 3 comments
trafficstars

I added a time column as explained in the user documentation but this adds the end timestamp. The following seems to achieve more what I want. Some feedback would be great and maybe it is worth updating the documentation?

import pytest
from datetime import datetime


def pytest_html_results_table_header(cells):
    cells.insert(2, '<th class="sortable time" data-column-type="time">Time</th>')


def pytest_html_results_table_row(report, cells):
    start = datetime.fromtimestamp(report.start)
    cells.insert(2, f'<td class="col-time">{start}</td>')


@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    report.start = call.start

I am still a bit unsure about the different phases of a test like setup, call and teardown. Maybe this needs extra handling?

sturmf avatar Nov 07 '23 07:11 sturmf

The example in the documentation is just that, an example.

If we change it, then someone will come along and want the end time - and around we go.

I think your solution looks good, if it achieves what you're looking for. :+1:

BeyondEvil avatar Nov 07 '23 11:11 BeyondEvil

@BeyondEvil Yes I understand that. My expectation for the time column was just wrong and I only noticed it when I saw that the duration added did not match the next timestamp. So maybe the suggestion would be to just add in the docu instead of 'adds a sortable time column' to ' adds a sortable end time column'. But I am also ok with just closing it.

sturmf avatar Nov 09 '23 09:11 sturmf

I'll accept a PR with that change. :)

BeyondEvil avatar Nov 09 '23 10:11 BeyondEvil