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
5 changes: 1 addition & 4 deletions pytest_html/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ def pytest_unconfigure(config):


def data_uri(content, mime_type='text/plain', charset='utf-8'):
if PY3:
data = b64encode(content.encode(charset)).decode('ascii')
else:
data = b64encode(content)
data = b64encode(content.encode(charset)).decode('ascii')
return 'data:{0};charset={1};base64,{2}'.format(mime_type, charset, data)


Expand Down
21 changes: 10 additions & 11 deletions testing/test_pytest_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,10 @@ def pytest_runtest_makereport(item, call):
assert result.ret == 0
assert content in html

def test_extra_text(self, testdir):
content = str(random.random())
@pytest.mark.parametrize('content, encoded', [
("u'\u0081'", 'woE='),
("'foo'", 'Zm9v')])
def test_extra_text(self, testdir, content, encoded):
testdir.makeconftest("""
import pytest
@pytest.mark.hookwrapper
Expand All @@ -246,16 +248,12 @@ def pytest_runtest_makereport(item, call):
report = outcome.get_result()
if report.when == 'call':
from pytest_html import extras
report.extra = [extras.text('{0}')]
report.extra = [extras.text({0})]
""".format(content))
testdir.makepyfile('def test_pass(): pass')
result, html = run(testdir, 'report.html', '--self-contained-html')
assert result.ret == 0
if PY3:
data = b64encode(content.encode('utf-8')).decode('ascii')
else:
data = b64encode(content)
href = 'data:text/plain;charset=utf-8;base64,{0}'.format(data)
href = 'data:text/plain;charset=utf-8;base64,{0}'.format(encoded)
link = '<a class="text" href="{0}" target="_blank">Text</a>'.format(
href)
assert link in html
Expand Down Expand Up @@ -327,7 +325,8 @@ 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_text_separated(self, testdir):
@pytest.mark.parametrize('content', [("u'\u0081'"), ("'foo'")])
def test_extra_text_separated(self, testdir, content):
testdir.makeconftest("""
import pytest
@pytest.mark.hookwrapper
Expand All @@ -336,8 +335,8 @@ def pytest_runtest_makereport(item, call):
report = outcome.get_result()
if report.when == 'call':
from pytest_html import extras
report.extra = [extras.text(u'\u0081')]
""")
report.extra = [extras.text({0})]
""".format(content))
testdir.makepyfile('def test_pass(): pass')
result, html = run(testdir)
hash_key = ('test_extra_text_separated.py::'
Expand Down