@@ -102,28 +102,25 @@ You can edit the *Summary* section by using the :code:`pytest_html_results_summa
102
102
103
103
.. code-block :: python
104
104
105
- from py.xml import html
106
-
107
-
108
105
def pytest_html_results_summary (prefix , summary , postfix ):
109
106
prefix.extend([" <p>foo: bar</p>" ])
110
107
111
108
Extra content
112
109
~~~~~~~~~~~~~
113
110
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
115
112
report object. Here are the types of extra content that can be added:
116
113
117
114
========== ============================================
118
115
Type Example
119
116
========== ============================================
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') ``
127
124
========== ============================================
128
125
129
126
**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:
138
135
============ ====================
139
136
Image format Example
140
137
============ ====================
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) ``
144
141
============ ====================
145
142
146
143
The following example adds the various types of extras using a
@@ -150,42 +147,44 @@ conftest.py file:
150
147
.. code-block :: python
151
148
152
149
import pytest
150
+ import pytest_html
153
151
154
152
155
153
@pytest.hookimpl (hookwrapper = True )
156
154
def pytest_runtest_makereport (item , call ):
157
- pytest_html = item.config.pluginmanager.getplugin(" html" )
158
155
outcome = yield
159
156
report = outcome.get_result()
160
- extra = getattr (report, " extra " , [])
157
+ extras = getattr (report, " extras " , [])
161
158
if report.when == " call" :
162
159
# 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/" ))
164
161
xfail = hasattr (report, " wasxfail" )
165
162
if (report.skipped and xfail) or (report.failed and not xfail):
166
163
# 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
169
166
170
167
You can also specify the :code: `name ` argument for all types other than :code: `html ` which will change the title of the
171
168
created hyper link:
172
169
173
170
.. code-block :: python
174
171
175
- extra .append(pytest_html.extras.text(" some string" , name = " Different title" ))
172
+ extras .append(pytest_html.extras.text(" some string" , name = " Different title" ))
176
173
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
178
175
in a test function without implementing hooks. These will generally end up
179
176
before any extras added by plugins.
180
177
181
178
.. code-block :: python
182
179
183
- from pytest_html import extras
180
+ import pytest_html
181
+
184
182
183
+ def test_extra (extras ):
184
+ extras.append(pytest_html.extras.text(" some string" ))
185
185
186
- def test_extra (extra ):
187
- extra.append(extras.text(" some string" ))
188
186
187
+ .. _modifying-results-table :
189
188
190
189
Modifying the results table
191
190
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -196,7 +195,6 @@ adds a sortable time column, and removes the links column:
196
195
197
196
.. code-block :: python
198
197
199
- from datetime import datetime
200
198
import pytest
201
199
202
200
@@ -232,9 +230,6 @@ additional HTML and log output with a notice that the log is empty:
232
230
233
231
.. code-block :: python
234
232
235
- from py.xml import html
236
-
237
-
238
233
def pytest_html_results_table_html (report , data ):
239
234
if report.passed:
240
235
del data[:]
@@ -243,6 +238,8 @@ additional HTML and log output with a notice that the log is empty:
243
238
Display options
244
239
---------------
245
240
241
+ .. _render-collapsed :
242
+
246
243
Auto Collapsing Table Rows
247
244
~~~~~~~~~~~~~~~~~~~~~~~~~~
248
245
0 commit comments