diff --git a/pytest_html/plugin.py b/pytest_html/plugin.py
index 60716d0e..02b14378 100644
--- a/pytest_html/plugin.py
+++ b/pytest_html/plugin.py
@@ -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 @@ 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 '
diff --git a/testing/test_pytest_html.py b/testing/test_pytest_html.py
index 8ca403de..a01a4799 100644
--- a/testing/test_pytest_html.py
+++ b/testing/test_pytest_html.py
@@ -326,6 +326,12 @@ def pytest_runtest_makereport(item, call):
src = 'data:{0};base64,{1}'.format(mime_type, content)
assert '
'.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'"),
diff --git a/tox.ini b/tox.ini
index 24080d92..7cd735fe 100644
--- a/tox.ini
+++ b/tox.ini
@@ -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]