Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pytest_html/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import absolute_import

from base64 import b64encode, b64decode
from os.path import isfile
import datetime
import json
import os
Expand Down Expand Up @@ -159,8 +160,14 @@ def append_extra_html(self, extra, extra_index, test_index):
href = None
if extra.get('format') == extras.FORMAT_IMAGE:
content = extra.get('content')
if content.startswith(('file', 'http')) or \
os.path.isfile(content):
try:
is_uri_or_path = (content.startswith(('file', 'http')) or
isfile(content))
except ValueError:
# On Windows, os.path.isfile throws this exception when
# passed a b64 encoded image.
is_uri_or_path = False
if is_uri_or_path:
if self.self_contained:
warnings.warn('Self-contained HTML report '
'includes link to external '
Expand Down
6 changes: 6 additions & 0 deletions testing/test_pytest_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ def pytest_runtest_makereport(item, call):
src = 'data:{0};base64,{1}'.format(mime_type, content)
assert '<img src="{0}"/>'.format(src) in html

def test_extra_image_windows(self, mocker, testdir):
mock_isfile = mocker.patch('pytest_html.plugin.isfile')
mock_isfile.side_effect = ValueError('stat: path too long for Windows')
self.test_extra_image(testdir, 'image/png', 'png')
assert mock_isfile.call_count == 1

@pytest.mark.parametrize('content', [
("u'\u0081'"),
("'foo'"),
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ commands = pytest -v -r a {posargs}
deps =
pytest-xdist
pytest-rerunfailures
pytest-mock
py{27,36,py,py3}-ansi2html: ansi2html

[testenv:flake8]
Expand Down