Fix for including a screenshot bug on Windows (#136)

Fixes #124
This commit is contained in:
Jeffry Pincus 2018-01-04 07:48:33 -05:00 committed by Dave Hunt
parent 764ef3cbbe
commit c61dc5bbe0
3 changed files with 16 additions and 2 deletions

View File

@ -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
@ -159,8 +160,14 @@ class HTMLReport(object):
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 '

View File

@ -326,6 +326,12 @@ class TestHTML:
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'"),

View File

@ -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]