-
Notifications
You must be signed in to change notification settings - Fork 243
Added support for bytes objects in Python 3.x #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,6 +202,31 @@ def pytest_runtest_makereport(item, call): | |
href) | ||
assert link in html | ||
|
||
@pytest.mark.xfail( | ||
sys.version_info < (3, 2), | ||
reason='Only affects Python versions later than 3.2', | ||
run=False) | ||
def test_extra_bytes(self, testdir): | ||
content = bytes(str(random.random()), 'utf-8') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will give you a bytes-object with a random number in it - not sure how useful that is? 😉 Also, the more idiomatic way to do this would be |
||
testdir.makeconftest(""" | ||
import pytest | ||
@pytest.mark.hookwrapper | ||
def pytest_runtest_makereport(item, call): | ||
outcome = yield | ||
report = outcome.get_result() | ||
if report.when == 'call': | ||
from pytest_html import extras | ||
report.extra = [extras.text({0})] | ||
""".format(content)) | ||
testdir.makepyfile('def test_pass(): pass') | ||
result, html = run(testdir) | ||
assert result.ret == 0 | ||
data = b64encode(content).decode('ascii') | ||
href = 'data:text/plain;charset=utf-8;base64,{0}'.format(data) | ||
link = '<a class="text" href="{0}" target="_blank">Text</a>'.format( | ||
href) | ||
assert link in html | ||
|
||
def test_extra_url(self, testdir): | ||
content = str(random.random()) | ||
testdir.makeconftest(""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will work, but is generally frowned upon - I'm not familiar enough with the context though to say if it'd make more sense to do it like this, or e.g. add a
data_uri_bytes
.