Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sturmf opened this issue Nov 7, 2023 · 3 comments
Open

Comments

@sturmf
Copy link

sturmf commented Nov 7, 2023

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?

@BeyondEvil
Copy link
Contributor

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. 👍

@sturmf
Copy link
Author

sturmf commented Nov 9, 2023

@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.

@BeyondEvil
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants