Skip to content

Commit b52135d

Browse files
committed
Remove screenshot links when creating a self contained report
The links are not needed, and they either cause duplication of large data URIs or a need for JavaScript
1 parent 34b49db commit b52135d

File tree

3 files changed

+9
-36
lines changed

3 files changed

+9
-36
lines changed

pytest_html/plugin.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,17 @@ def append_extra_html(self, extra, extra_index, test_index):
158158
href = None
159159
if extra.get('format') == extras.FORMAT_IMAGE:
160160
if self.self_contained:
161-
image_src = 'data:image/png;base64,{0}'.format(
161+
src = 'data:image/png;base64,{0}'.format(
162162
extra.get('content'))
163-
href = '#'
163+
self.additional_html.append(html.div(
164+
html.img(src=src), class_='image'))
164165
else:
165166
content = b64decode(extra.get('content'))
166-
href = self.create_asset(content, extra_index,
167-
test_index, 'png', 'wb')
168-
image_src = href
169-
self.additional_html.append(html.div(
170-
html.a(html.img(src=image_src), href=href),
171-
class_='image'))
167+
href = src = self.create_asset(
168+
content, extra_index, test_index, 'png', 'wb')
169+
self.additional_html.append(html.div(
170+
html.a(html.img(src=src), href=href),
171+
class_='image'))
172172

173173
elif extra.get('format') == extras.FORMAT_HTML:
174174
self.additional_html.append(html.div(

pytest_html/resources/main.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -106,32 +106,6 @@ addEventListener("DOMContentLoaded", function() {
106106

107107
toggle_sort_states(find('.initial-sort'));
108108

109-
find_all('.col-links a.image').forEach(function(elem) {
110-
elem.addEventListener("click",
111-
function(event) {
112-
var node = elem;
113-
while (node && !node.classList.contains('results-table-row')) {
114-
node = node.parentNode;
115-
}
116-
if (node != null) {
117-
if (node.nextSibling &&
118-
node.nextSibling.classList.contains("extra")) {
119-
var href = find('.image img', node.nextSibling).src;
120-
window.open(href);
121-
}
122-
}
123-
event.preventDefault();
124-
}, false)
125-
});
126-
127-
find_all('.image a').forEach(function(elem) {
128-
elem.addEventListener("click",
129-
function(event) {
130-
window.open(find('img', elem).getAttribute('src'));
131-
event.preventDefault();
132-
}, false)
133-
});
134-
135109
find_all('.sortable').forEach(function(elem) {
136110
elem.addEventListener("click",
137111
function(event) {

test_pytest_html.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,8 @@ def pytest_runtest_makereport(item, call):
320320
testdir.makepyfile('def test_pass(): pass')
321321
result, html = run(testdir, 'report.html', '--self-contained-html')
322322
assert result.ret == 0
323-
assert '<a class="image" href="#" target="_blank">Image</a>' in html
324323
src = 'data:image/png;base64,{0}'.format(content)
325-
assert '<a href="#"><img src="{0}"/></a>'.format(src) in html
324+
assert '<img src="{0}"/>'.format(src) in html
326325

327326
@pytest.mark.parametrize('file_extension,file_type',
328327
[('png', 'image'),

0 commit comments

Comments
 (0)