Repository navigation
Is it possible to change the duration format from just seconds to something like hh:mm:ss? #376
Description
Activity
- addedquestionThis PR is asking whether it is possible to achieve a certain outcomeThis PR is asking whether it is possible to achieve a certain outcome
on Nov 22, 2020 Hi @brettnolan let me look into this for you
@brettnolan can you paste the output of
pip listplease?durationcomes from the pytest api and must always be in seconds which is why you are getting the error you are seeing.However, I think it would make sense for pytest-html to do the formatting on your behalf ( I don't really see a reason why 3721 is clearer than 01:02:01, for example )
I'll have a PR up in a day or two for this
- addedenhancementThis issue/PR relates to a feature request.This issue/PR relates to a feature request.
on Nov 22, 2020 Thanks!
Here is the 'pip list' output:
Package Version
apipkg 1.5
attrs 20.2.0
certifi 2020.6.20
click 7.1.2
click-completion 0.5.2
colorama 0.4.3
coverage 5.3
crayons 0.4.0
cycler 0.10.0
decorator 4.4.2
execnet 1.7.1
imageio 2.9.0
importlib-metadata 1.7.0
iniconfig 1.0.1
Jinja2 2.11.2
keyboard 0.13.5
kiwisolver 1.2.0
MarkupSafe 1.1.1
matplotlib 3.3.2
more-itertools 8.5.0
networkx 2.5
numpy 1.19.2
opencv-python 4.4.0.42
packaging 20.4
Pillow 7.2.0
pip 20.2.3
pkg-resources 0.0.0
pluggy 0.13.1
py 1.9.0
pycycle 0.0.8
pyparsing 2.4.7
pytesseract 0.3.6
pytest 6.0.1
pytest-cov 2.10.1
pytest-forked 1.3.0
pytest-html 2.1.1
pytest-metadata 1.10.0
pytest-rerunfailures 9.1.1
pytest-xdist 2.1.0
python-dateutil 2.8.1
PyWavelets 1.1.1
scikit-image 0.17.2
scipy 1.5.2
setuptools 50.3.2
shellingham 1.3.2
six 1.15.0
tifffile 2020.9.3
toml 0.10.1
uiautomator 0.3.6
urllib3 1.25.10
zipp 3.1.0Hey @brettnolan this functionality is now on the master branch and documentation for it can be found here.
Thanks for raising this issue!
Hi @brettnolan you can get this functionality by installing the latest version of pytest-html from PyPI
Formatting the Duration Column
The formatting of the timestamp used in the Durations column can be modified by setting duration_formatter on the report attribute. All time.strftime formatting directives are supported. In addition, it is possible to supply %f to get duration milliseconds. If this value is not set, the values in the Durations column are displayed in %S.%f format where %S is the total number of seconds a test ran for.Below is an example of a conftest.py file setting duration_formatter:
`import pytest
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
setattr(report, "duration_formatter", "%H:%M:%S.%f")`NOTE: Milliseconds are always displayed with a precision of 2
For future readers of this: The support for duration formatting has been removed in v4.
If there's enough interest in re-implementing support, we will provide a way for you to, via a hook for example, to provide your own formatting functionality.
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
However, plugin.py didn't like the format