Skip to content

Commit 34b49db

Browse files
committed
Write images as bytes
1 parent 5ca3827 commit 34b49db

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

pytest_html/plugin.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def __lt__(self, other):
136136
return order.index(self.outcome) < order.index(other.outcome)
137137

138138
def create_asset(self, content, extra_index,
139-
test_index, file_extension):
139+
test_index, file_extension, mode='w'):
140140
hash_key = ''.join([self.test_id, str(extra_index),
141141
str(test_index)]).encode('utf-8')
142142
hash_generator = hashlib.md5()
@@ -150,7 +150,7 @@ def create_asset(self, content, extra_index,
150150

151151
relative_path = '{0}/{1}'.format('assets', asset_file_name)
152152

153-
with open(asset_path, 'w') as f:
153+
with open(asset_path, mode) as f:
154154
f.write(content)
155155
return relative_path
156156

@@ -162,12 +162,9 @@ def append_extra_html(self, extra, extra_index, test_index):
162162
extra.get('content'))
163163
href = '#'
164164
else:
165-
content = extra.get('content')
166-
if PY3:
167-
content = bytearray(extra.get('content'), 'utf-8')
168-
content = str(b64decode(content))
165+
content = b64decode(extra.get('content'))
169166
href = self.create_asset(content, extra_index,
170-
test_index, 'png')
167+
test_index, 'png', 'wb')
171168
image_src = href
172169
self.additional_html.append(html.div(
173170
html.a(html.img(src=image_src), href=href),

0 commit comments

Comments
 (0)