Skip to content

Commit 377514a

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

File tree

7 files changed

+152
-105
lines changed

7 files changed

+152
-105
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: 113 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,125 @@ on:
44
workflow_call:
55

66
jobs:
7-
test_python:
8-
name: ${{ matrix.python-version }}
7+
test_javascript:
8+
name: javascript
99
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Use Node.js
13+
uses: actions/setup-node@v3
14+
with:
15+
node-version: '16.x'
16+
- name: Install dependencies
17+
run: npm ci
18+
- name: Run tests
19+
run: npm run unit
20+
21+
test_unit:
22+
name: ${{ matrix.os }} - ${{ matrix.python-version }}
23+
runs-on: ${{ matrix.os }}
1024
strategy:
1125
fail-fast: false
1226
matrix:
27+
os: [ubuntu-latest, windows-latest, macos-latest]
28+
python-version: ["3.7", "3.8", "3.9", "3.10"]
1329
include:
14-
- tox-env: "py37"
15-
python-version: "3.7"
16-
17-
# https://github.com/pytest-dev/pytest-html/issues/585
18-
# - os: windows-latest
19-
# name: py37-windows
20-
# python-version: 3.7
30+
- os: ubuntu-latest
31+
python-version: "3.10"
32+
with-coverage: true
33+
34+
- os: ubuntu-latest
35+
python-version: pypy3.9
36+
tox-env: py3.9
37+
- os: windows-latest
38+
python-version: pypy3.9
39+
tox-env: py3.9
40+
- os: macos-latest
41+
python-version: pypy3.9
42+
tox-env: py3.9
43+
44+
- os: ubuntu-latest
45+
python-version: 3.11-dev
46+
tox-env: devel
47+
- os: windows-latest
48+
python-version: 3.11-dev
49+
tox-env: devel
50+
- os: macos-latest
51+
python-version: 3.11-dev
52+
tox-env: devel
2153

22-
# https://github.com/pytest-dev/pytest-html/issues/585
23-
# - os: macOS-latest
24-
# name: py37-mac
25-
# python-version: 3.7
54+
steps:
55+
- name: Set newline behavior
56+
run: git config --global core.autocrlf false
2657

27-
- tox-env: "py38"
28-
python-version: "3.8"
58+
- uses: actions/checkout@v3
2959

30-
# https://github.com/pytest-dev/pytest-html/issues/585
31-
# - os: windows-latest
32-
# name: py38-windows
33-
# python-version: 3.8
60+
- name: Use Node.js
61+
uses: actions/setup-node@v3
62+
with:
63+
node-version: '16.x'
3464

35-
# https://github.com/pytest-dev/pytest-html/issues/585
36-
# - os: macOS-latest
37-
# name: py38-mac
38-
# python-version: 3.8
65+
- name: Install dependencies
66+
run: npm ci
3967

40-
- tox-env: "py39"
41-
python-version: "3.9"
68+
- name: Build app
69+
run: npm run build:ci
4270

43-
- tox-env: "py310"
44-
python-version: "3.10"
71+
- name: Set up python
72+
uses: actions/setup-python@v4
73+
with:
74+
python-version: ${{ matrix.python-version }}
4575

46-
# https://github.com/pytest-dev/pytest-html/issues/585
47-
# - os: windows-latest
48-
# name: py39-windows
49-
# python-version: 3.9
76+
- name: Install tox
77+
run: python -m pip install --upgrade tox
5078

51-
# https://github.com/pytest-dev/pytest-html/issues/585
52-
# - os: macOS-latest
53-
# name: py39-mac
54-
# python-version: 3.9
79+
- name: Run unit tests
80+
if: ${{ ! matrix.tox-env && matrix.with-coverage }}
81+
run: tox -e py${{ matrix.python-version }}-cov -- testing/test_unit.py
5582

56-
- tox-env: "pypy3"
57-
python-version: "pypy3.9"
58-
skip-coverage: true
83+
- name: Run unit tests
84+
if: ${{ ! matrix.tox-env && ! matrix.with-coverage }}
85+
run: tox -e py${{ matrix.python-version }} -- testing/test_unit.py
5986

60-
# https://github.com/pytest-dev/pytest-html/issues/585
61-
# - os: windows-latest
62-
# name: pypy3-windows
63-
# python-version: pypy3
87+
- name: Run unit tests
88+
if: ${{ matrix.tox-env }}
89+
run: tox -e ${{ matrix.tox-env }} -- testing/test_unit.py
6490

65-
# https://github.com/pytest-dev/pytest-html/issues/482
66-
# - os: macOS-latest
67-
# name: pypy3-mac
68-
# python-version: pypy-3.8
91+
- name: Upload coverage to codecov
92+
if: >-
93+
${{
94+
! github.event.schedule &&
95+
matrix.with-coverage &&
96+
github.repository_owner == 'pytest-dev'
97+
}}
98+
uses: codecov/codecov-action@v3
99+
with:
100+
fail_ci_if_error: true
101+
files: ./coverage.xml
102+
flags: tests
103+
name: ${{ matrix.os }}-${{ matrix.python-version }}
104+
verbose: true
69105

70-
- tox-env: "devel"
71-
python-version: "3.11-dev"
106+
test_integration:
107+
name: ubuntu - ${{ matrix.python-version }}
108+
needs:
109+
- test_javascript
110+
- test_unit
111+
runs-on: ubuntu-latest
112+
strategy:
113+
fail-fast: false
114+
matrix:
115+
python-version: ["3.7", "3.8", "3.9", "3.10"]
116+
include:
117+
- python-version: "3.10"
118+
with-coverage: true
119+
- python-version: pypy3.9
120+
tox-env: py3.9
121+
- python-version: 3.11-dev
122+
tox-env: devel
72123

73124
steps:
74-
- name: Set Newline Behavior
125+
- name: Set newline behavior
75126
run: git config --global core.autocrlf false
76127

77128
- uses: actions/checkout@v3
@@ -84,34 +135,38 @@ jobs:
84135
with:
85136
node-version: '16.x'
86137

87-
- name: Install Dependencies
138+
- name: Install dependencies
88139
run: npm ci
89140

90141
- name: Build app
91142
run: npm run build:ci
92143

93-
- name: Set up Python
144+
- name: Set up python
94145
uses: actions/setup-python@v4
95146
with:
96147
python-version: ${{ matrix.python-version }}
97148

98149
- name: Install tox
99150
run: python -m pip install --upgrade tox
100151

101-
- name: Test with coverage
102-
if: ${{ ! matrix.skip-coverage }}
103-
run: tox -e ${{ matrix.tox-env }}-cov
152+
- name: Run integration tests
153+
if: ${{ ! matrix.tox-env && matrix.with-coverage }}
154+
run: tox -e ${{ matrix.python-version }}-cov -- testing/test_integration.py
104155

105-
- name: Test without coverage
106-
if: ${{ matrix.skip-coverage }}
107-
run: tox -e ${{ matrix.tox-env }}
156+
- name: Run integration tests
157+
if: ${{ ! matrix.tox-env && ! matrix.with-coverage }}
158+
run: tox -e ${{ matrix.python-version }} -- testing/test_integration.py
159+
160+
- name: Run integration tests
161+
if: ${{ matrix.tox-env }}
162+
run: tox -e ${{ matrix.tox-env }} -- testing/test_integration.py
108163

109164
# TODO: https://github.com/pytest-dev/pytest-html/issues/481
110165
- name: Upload coverage to codecov
111166
if: >-
112167
${{
113168
! github.event.schedule &&
114-
! matrix.skip-coverage &&
169+
matrix.with-coverage &&
115170
github.repository_owner == 'pytest-dev'
116171
}}
117172
uses: codecov/codecov-action@v3
@@ -121,17 +176,3 @@ jobs:
121176
flags: tests
122177
name: ${{ matrix.tox-env }}
123178
verbose: true
124-
125-
test_javascript:
126-
name: mocha
127-
runs-on: ubuntu-latest
128-
steps:
129-
- uses: actions/checkout@v3
130-
- name: Use Node.js
131-
uses: actions/setup-node@v3
132-
with:
133-
node-version: '16.x'
134-
- name: Install Dependencies
135-
run: npm ci
136-
- name: Mocha Tests
137-
run: npm run unit

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)