Skip to content

Commit 98e8632

Browse files
committed
Docs: Add Deprecations docs
1 parent 43175f1 commit 98e8632

File tree

4 files changed

+192
-29
lines changed

4 files changed

+192
-29
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212

1313
concurrency:
1414
group: ${{ github.workflow }}-${{ github.ref }}
15-
cancel-in-progress: ${{ github.ref != github.event.repository.default_branch }}
15+
cancel-in-progress: ${{ ! contains(github.ref, github.event.repository.default_branch) }}
1616

1717
jobs:
1818
build_docs:

docs/deprecations.rst

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
User Guide
2+
==========
3+
4+
Deprecation policy
5+
------------------
6+
7+
If not otherwise explicitly stated, deprecations are removed in the next major version.
8+
9+
Deprecations
10+
-------------------------------------
11+
12+
duration_formatter
13+
~~~~~~~~~~~~~~~~~~
14+
15+
Deprecated in ``4.0.0``
16+
17+
*'duration_formatter' has been removed and no longer has any effect!*
18+
19+
Reason
20+
^^^^^^
21+
22+
With the rewrite of the plugin where most of the logic was moved to javascript,
23+
the disconnect between time formatting between python and javascript made it
24+
untenable to support dynamically setting the format.
25+
26+
The decision was made to have ``ms`` for durations under 1 second,
27+
and ``HH:mm:ss`` for 1 second and above.
28+
29+
Mitigation
30+
^^^^^^^^^^
31+
32+
Currently none.
33+
34+
render_collapsed
35+
~~~~~~~~~~~~~~~~
36+
37+
Deprecated in ``4.0.0``
38+
39+
*'render_collapsed = True' is deprecated and support will be removed in the next major release.
40+
Please use 'render_collapsed = all' instead.*
41+
42+
Reason
43+
^^^^^^
44+
45+
We've changed the ini-config to better match the query param, so now the ini-config takes the same
46+
values as the query param. For valid values please see :ref:`render-collapsed`.
47+
48+
Mitigation
49+
^^^^^^^^^^
50+
51+
Setting ``render_collapsed`` to ``all`` is equivalent to previously setting it to ``True``.
52+
53+
.. _report-extra:
54+
55+
report.extra
56+
~~~~~~~~~~~~
57+
58+
Deprecated in ``4.0.0``
59+
60+
*The 'report.extra' attribute is deprecated and will be removed in a future release,
61+
use 'report.extras' instead.*
62+
63+
Reason
64+
^^^^^^
65+
66+
The ``extra`` attribute is of type ``list``, hence more appropriately named ``extras``.
67+
68+
Mitigation
69+
^^^^^^^^^^
70+
71+
Rename ``extra`` to ``extras``.
72+
73+
extra fixture
74+
~~~~~~~~~~~~~
75+
76+
Deprecated in ``4.0.0``
77+
78+
*The 'extra' fixture is deprecated and will be removed in a future release,
79+
use 'extras' instead.*
80+
81+
Reason
82+
^^^^^^
83+
84+
See :ref:`report-extra`
85+
86+
Mitigation
87+
^^^^^^^^^^
88+
89+
Rename ``extra`` to ``extras``.
90+
91+
cell list assignment
92+
~~~~~~~~~~~~~~~~~~~~
93+
94+
Deprecated in ``4.0.0``
95+
96+
*list-type assignment is deprecated and support will be removed in a future release.
97+
Please use 'insert()' instead.*
98+
99+
Reason
100+
^^^^^^
101+
102+
The `cells` argument in the table manipulation hooks (see :ref:`modifying-results-table`) was
103+
previously of type `list` but is now an object.
104+
105+
Mitigation
106+
^^^^^^^^^^
107+
108+
Replace ``cells[4] = value`` with ``cells.insert(4, value)``.
109+
110+
py module
111+
~~~~~~~~~
112+
113+
Deprecated in ``4.0.0``
114+
115+
*The 'py' module is deprecated and support will be removed in a future release.*
116+
117+
Reason
118+
^^^^^^
119+
120+
The ``py`` module is in maintenance mode and has been removed as a dependency.
121+
122+
Mitigation
123+
^^^^^^^^^^
124+
125+
Any usage of the ``html`` module from ``py.xml``, should be replaced with something
126+
that returns the HTML as a string.
127+
128+
From:
129+
130+
.. code-block:: python
131+
132+
import pytest
133+
from py.xml import html
134+
135+
136+
def pytest_html_results_table_header(cells):
137+
cells.insert(2, html.th("Description"))
138+
cells.insert(
139+
1, html.th("Time", class_="sortable time", data - column - type="time")
140+
)
141+
142+
To:
143+
144+
.. code-block:: python
145+
146+
import pytest
147+
148+
149+
def pytest_html_results_table_header(cells):
150+
cells.insert(2, "<th>Description</th>")
151+
cells.insert(1, '<th class="sortable time" data-column-type="time">Time</th>')
152+
153+
Note that you can keep using the `py` module by simple wrapping it in ``str``:
154+
155+
.. code-block:: python
156+
157+
import pytest
158+
from py.xml import html
159+
160+
161+
def pytest_html_results_table_header(cells):
162+
cells.insert(2, str(html.th("Description")))
163+
cells.insert(
164+
1, str(html.th("Time", class_="sortable time", data - column - type="time"))
165+
)

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ pytest-html is a plugin for `pytest`_ that generates a HTML report for test resu
1717
api_reference
1818
development
1919
changelog
20+
deprecations
2021

2122
.. _pytest: http://pytest.org

docs/user_guide.rst

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,25 @@ You can edit the *Summary* section by using the :code:`pytest_html_results_summa
102102

103103
.. code-block:: python
104104
105-
from py.xml import html
106-
107-
108105
def pytest_html_results_summary(prefix, summary, postfix):
109106
prefix.extend(["<p>foo: bar</p>"])
110107
111108
Extra content
112109
~~~~~~~~~~~~~
113110

114-
You can add details to the HTML report by creating an 'extra' list on the
111+
You can add details to the HTML report by creating an 'extras' list on the
115112
report object. Here are the types of extra content that can be added:
116113

117114
========== ============================================
118115
Type Example
119116
========== ============================================
120-
Raw HTML ``extra.html('<div>Additional HTML</div>')``
121-
`JSON`_ ``extra.json({'name': 'pytest'})``
122-
Plain text ``extra.text('Add some simple Text')``
123-
URL ``extra.url('http://www.example.com/')``
124-
Image ``extra.image(image, mime_type='image/gif', extension='gif')``
125-
Image ``extra.image('/path/to/file.png')``
126-
Image ``extra.image('http://some_image.png')``
117+
Raw HTML ``extras.html('<div>Additional HTML</div>')``
118+
`JSON`_ ``extras.json({'name': 'pytest'})``
119+
Plain text ``extras.text('Add some simple Text')``
120+
URL ``extras.url('http://www.example.com/')``
121+
Image ``extras.image(image, mime_type='image/gif', extension='gif')``
122+
Image ``extras.image('/path/to/file.png')``
123+
Image ``extras.image('http://some_image.png')``
127124
========== ============================================
128125

129126
**Note**: When adding an image from file, the path can be either absolute
@@ -138,9 +135,9 @@ There are also convenient types for several image formats:
138135
============ ====================
139136
Image format Example
140137
============ ====================
141-
PNG ``extra.png(image)``
142-
JPEG ``extra.jpg(image)``
143-
SVG ``extra.svg(image)``
138+
PNG ``extras.png(image)``
139+
JPEG ``extras.jpg(image)``
140+
SVG ``extras.svg(image)``
144141
============ ====================
145142

146143
The following example adds the various types of extras using a
@@ -150,42 +147,44 @@ conftest.py file:
150147
.. code-block:: python
151148
152149
import pytest
150+
import pytest_html
153151
154152
155153
@pytest.hookimpl(hookwrapper=True)
156154
def pytest_runtest_makereport(item, call):
157-
pytest_html = item.config.pluginmanager.getplugin("html")
158155
outcome = yield
159156
report = outcome.get_result()
160-
extra = getattr(report, "extra", [])
157+
extras = getattr(report, "extras", [])
161158
if report.when == "call":
162159
# always add url to report
163-
extra.append(pytest_html.extras.url("http://www.example.com/"))
160+
extras.append(pytest_html.extras.url("http://www.example.com/"))
164161
xfail = hasattr(report, "wasxfail")
165162
if (report.skipped and xfail) or (report.failed and not xfail):
166163
# only add additional html on failure
167-
extra.append(pytest_html.extras.html("<div>Additional HTML</div>"))
168-
report.extra = extra
164+
extras.append(pytest_html.extras.html("<div>Additional HTML</div>"))
165+
report.extras = extras
169166
170167
You can also specify the :code:`name` argument for all types other than :code:`html` which will change the title of the
171168
created hyper link:
172169

173170
.. code-block:: python
174171
175-
extra.append(pytest_html.extras.text("some string", name="Different title"))
172+
extras.append(pytest_html.extras.text("some string", name="Different title"))
176173
177-
It is also possible to use the fixture :code:`extra` to add content directly
174+
It is also possible to use the fixture :code:`extras` to add content directly
178175
in a test function without implementing hooks. These will generally end up
179176
before any extras added by plugins.
180177

181178
.. code-block:: python
182179
183-
from pytest_html import extras
180+
import pytest_html
181+
184182
183+
def test_extra(extras):
184+
extras.append(pytest_html.extras.text("some string"))
185185
186-
def test_extra(extra):
187-
extra.append(extras.text("some string"))
188186
187+
.. _modifying-results-table:
189188

190189
Modifying the results table
191190
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -196,7 +195,6 @@ adds a sortable time column, and removes the links column:
196195

197196
.. code-block:: python
198197
199-
from datetime import datetime
200198
import pytest
201199
202200
@@ -232,9 +230,6 @@ additional HTML and log output with a notice that the log is empty:
232230

233231
.. code-block:: python
234232
235-
from py.xml import html
236-
237-
238233
def pytest_html_results_table_html(report, data):
239234
if report.passed:
240235
del data[:]
@@ -243,6 +238,8 @@ additional HTML and log output with a notice that the log is empty:
243238
Display options
244239
---------------
245240

241+
.. _render-collapsed:
242+
246243
Auto Collapsing Table Rows
247244
~~~~~~~~~~~~~~~~~~~~~~~~~~
248245

0 commit comments

Comments
 (0)