Skip to content

Commit 08ff103

Browse files
committed
update: duration_format renders deprecation warning
1 parent df894ec commit 08ff103

File tree

4 files changed

+37
-32
lines changed

4 files changed

+37
-32
lines changed

docs/user_guide.rst

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -281,29 +281,6 @@ The following query parameters may be passed:
281281
* :code:`xpassed`
282282
* :code:`rerun`
283283

284-
Formatting the Duration Column
285-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
286-
287-
The formatting of the timestamp used in the :code:`Durations` column can be modified by setting :code:`duration_formatter`
288-
on the :code:`report` attribute. All `time.strftime`_ formatting directives are supported. In addition, it is possible
289-
to supply :code:`%f` to get duration milliseconds. If this value is not set, the values in the :code:`Durations` column are
290-
displayed in :code:`%S.%f` format where :code:`%S` is the total number of seconds a test ran for.
291-
292-
Below is an example of a :code:`conftest.py` file setting :code:`duration_formatter`:
293-
294-
.. code-block:: python
295-
296-
import pytest
297-
298-
299-
@pytest.hookimpl(hookwrapper=True)
300-
def pytest_runtest_makereport(item, call):
301-
outcome = yield
302-
report = outcome.get_result()
303-
setattr(report, "duration_formatter", "%H:%M:%S.%f")
304-
305-
**NOTE**: Milliseconds are always displayed with a precision of 2
306-
307284
.. _@pytest.hookimpl(tryfirst=True): https://docs.pytest.org/en/stable/writing_plugins.html#hook-function-ordering-call-example
308285
.. _ansi2html: https://pypi.python.org/pypi/ansi2html/
309286
.. _Content Security Policy (CSP): https://developer.mozilla.org/docs/Web/Security/CSP/

src/pytest_html/nextgen.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ def insert(self, index, html):
4545
self._html[index] = html
4646

4747
class Report:
48-
def __init__(self, title, duration_format):
48+
def __init__(self, title):
4949
self._data = {
5050
"title": title,
5151
"collectedItems": 0,
5252
"runningState": "not_started",
53-
"durationFormat": duration_format,
5453
"environment": {},
5554
"tests": [],
5655
"resultsTableHeader": {},
@@ -84,11 +83,10 @@ def __init__(self, report_path, config, default_css="style.css"):
8483
self._css = _process_css(
8584
Path(self._resources_path, default_css), self._config.getoption("css")
8685
)
87-
self._duration_format = config.getini("duration_format")
8886
self._max_asset_filename_length = int(
8987
config.getini("max_asset_filename_length")
9088
)
91-
self._report = self.Report(self._report_path.name, self._duration_format)
89+
self._report = self.Report(self._report_path.name)
9290

9391
@property
9492
def css(self):
@@ -242,6 +240,12 @@ def pytest_collection_finish(self, session):
242240

243241
@pytest.hookimpl(trylast=True)
244242
def pytest_runtest_logreport(self, report):
243+
if hasattr(report, "duration_formatter"):
244+
warnings.warn(
245+
"'duration_format' has been removed and no longer has any effect!",
246+
DeprecationWarning,
247+
)
248+
245249
data = {
246250
"duration": report.duration,
247251
"when": report.when,

src/pytest_html/plugin.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ def pytest_addoption(parser):
4242
default=[],
4343
help="append given css file content to report style file.",
4444
)
45-
parser.addini(
46-
"duration_format",
47-
default=None,
48-
help="the format for duration.",
49-
)
5045
parser.addini(
5146
"render_collapsed",
5247
type="bool",

testing/test_unit.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
pytest_plugins = ("pytester",)
2+
3+
4+
def run(pytester, path="report.html", *args):
5+
path = pytester.path.joinpath(path)
6+
return pytester.runpytest("-s", "--html", path, *args)
7+
8+
9+
def test_duration_format_deprecation_warning(pytester):
10+
pytester.makeconftest(
11+
"""
12+
import pytest
13+
@pytest.hookimpl(hookwrapper=True)
14+
def pytest_runtest_makereport(item, call):
15+
outcome = yield
16+
report = outcome.get_result()
17+
setattr(report, "duration_formatter", "%H:%M:%S.%f")
18+
"""
19+
)
20+
pytester.makepyfile(
21+
"""
22+
import pytest
23+
def test_pass():
24+
with pytest.warns(DeprecationWarning) as record:
25+
assert len(record) == 1
26+
"""
27+
)
28+
result = run(pytester)
29+
assert result.ret == 0

0 commit comments

Comments
 (0)