Skip to content

Is it possible to change the duration format from just seconds to something like hh:mm:ss? #376

Closed
@brettnolan

Description

@brettnolan

Is there a way to format the duration time to something like:
HH:MM:SS
or
h hours, m mins, s secs

I tried doing it within here, by changing the attribute value

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    report.description = str(item.function.__doc__)

    # change duration format here
    duration = getattr(report, "duration", 0.0)                          
    converted_duration = timedelta(seconds=duration)
    setattr(report, "duration", converted_duration)

However, plugin.py didn't like the format

INTERNALERROR>   File python-virtual-environments/python3_env/lib/python3.6/site-packages/pytest_html/plugin.py", line 162, in __init__
INTERNALERROR>     html.td(f"{self.time:.2f}", class_="col-duration"),
INTERNALERROR> TypeError: unsupported format string passed to datetime.timedelta.__format__

Metadata

Metadata

Assignees

Labels

enhancementThis issue/PR relates to a feature request.questionThis PR is asking whether it is possible to achieve a certain outcome

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions