Skip to content

Commit cc97e9a

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

File tree

7 files changed

+119
-36
lines changed

7 files changed

+119
-36
lines changed

.github/workflows/actions.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ on:
1313
**
1414
pull_request:
1515

16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: true
19+
1620
jobs:
1721
build_docs:
1822
name: Build Docs

.github/workflows/tests.yml

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,85 @@ on:
44
workflow_call:
55

66
jobs:
7-
test_python:
7+
test_py_unit:
8+
name: ${{ matrix.os }} - ${{ matrix.python-version }}
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
os: [ubuntu-latest, windows-latest, macos-latest]
14+
python-version: ["3.7", "3.8", "3.9", "3.10"]
15+
include:
16+
- os: ubuntu-latest
17+
python-version: pypy3.9
18+
tox-env: py3.9
19+
- os: windows-latest
20+
python-version: pypy3.9
21+
tox-env: py3.9
22+
- os: macos-latest
23+
python-version: pypy3.9
24+
tox-env: py3.9
25+
26+
- os: ubuntu-latest
27+
python-version: 3.11-dev
28+
tox-env: devel
29+
- os: windows-latest
30+
python-version: 3.11-dev
31+
tox-env: devel
32+
- os: macos-latest
33+
python-version: 3.11-dev
34+
tox-env: devel
35+
36+
steps:
37+
- name: Set Newline Behavior
38+
run: git config --global core.autocrlf false
39+
40+
- uses: actions/checkout@v3
41+
42+
- name: Use Node.js
43+
uses: actions/setup-node@v3
44+
with:
45+
node-version: '16.x'
46+
47+
- name: Install Dependencies
48+
run: npm ci
49+
50+
- name: Build app
51+
run: npm run build:ci
52+
53+
- name: Set up Python
54+
uses: actions/setup-python@v4
55+
with:
56+
python-version: ${{ matrix.python-version }}
57+
58+
- name: Install tox
59+
run: python -m pip install --upgrade tox
60+
61+
- name: Run unit tests
62+
if: ${{ ! matrix.tox-env }}
63+
run: tox -e py${{ matrix.python-version }}-cov -- testing/test_unit.py
64+
65+
- name: Run unit tests
66+
if: ${{ matrix.tox-env }}
67+
run: tox -e ${{ matrix.tox-env }}-cov -- testing/test_unit.py
68+
69+
# - name: Upload coverage to codecov
70+
# if: >-
71+
# ${{
72+
# ! github.event.schedule &&
73+
# github.repository_owner == 'pytest-dev'
74+
# }}
75+
# uses: codecov/codecov-action@v3
76+
# with:
77+
# fail_ci_if_error: true
78+
# files: ./coverage.xml
79+
# flags: tests
80+
# name: ${{ matrix.os }}-${{ matrix.python-version }}
81+
# verbose: true
82+
83+
test_integration:
884
name: ${{ matrix.python-version }}
85+
needs: test_py_unit
986
runs-on: ubuntu-latest
1087
strategy:
1188
fail-fast: false
@@ -100,11 +177,11 @@ jobs:
100177

101178
- name: Test with coverage
102179
if: ${{ ! matrix.skip-coverage }}
103-
run: tox -e ${{ matrix.tox-env }}-cov
180+
run: tox -e ${{ matrix.tox-env }}-cov -- testing/test_integration.py
104181

105182
- name: Test without coverage
106183
if: ${{ matrix.skip-coverage }}
107-
run: tox -e ${{ matrix.tox-env }}
184+
run: tox -e ${{ matrix.tox-env }} -- testing/test_integration.py
108185

109186
# TODO: https://github.com/pytest-dev/pytest-html/issues/481
110187
- name: Upload coverage to codecov

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_formatter' 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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
pytest_plugins = ("pytester",)
2+
3+
4+
def run(pytester, path="report.html", *args):
5+
path = pytester.path.joinpath(path)
6+
return pytester.runpytest("--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("def test_pass(): pass")
21+
result = run(pytester)
22+
result.stdout.fnmatch_lines(
23+
[
24+
"*DeprecationWarning: 'duration_formatter'*",
25+
],
26+
)

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# and then run "tox" from this directory.
55

66
[tox]
7-
envlist = py{37,38,39,310,py3}, docs, linting
7+
envlist = py{3.7, 3.8, 3.9, 3.10, py3.9}, docs, linting
88
isolated_build = True
99

1010
[testenv]

0 commit comments

Comments
 (0)