summaryrefslogtreecommitdiff
path: root/testing/test_pastebin.py
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2015-12-03 20:07:18 -0200
committerBruno Oliveira <nicoddemus@gmail.com>2015-12-03 20:07:18 -0200
commit14bc3c40099a33a692b2f6ce0a0626698905d8fe (patch)
tree6b002e2f65deb0c61a31a6451f3e83694604c1df /testing/test_pastebin.py
parent7232b45f2555734dcbf2d14ea3d8c54625ff8426 (diff)
downloadpytest-14bc3c40099a33a692b2f6ce0a0626698905d8fe.tar.gz
Fix pastebin when captured output contains non-ascii characters
Fix #1219
Diffstat (limited to 'testing/test_pastebin.py')
-rw-r--r--testing/test_pastebin.py35
1 files changed, 31 insertions, 4 deletions
diff --git a/testing/test_pastebin.py b/testing/test_pastebin.py
index 2fe4bc137..03570a5c7 100644
--- a/testing/test_pastebin.py
+++ b/testing/test_pastebin.py
@@ -1,3 +1,4 @@
+# encoding: utf-8
import sys
import pytest
@@ -27,6 +28,7 @@ class TestPasteCapture:
assert reprec.countoutcomes() == [1,1,1]
def test_all(self, testdir, pastebinlist):
+ from _pytest.pytester import LineMatcher
testpath = testdir.makepyfile("""
import pytest
def test_pass():
@@ -39,9 +41,34 @@ class TestPasteCapture:
reprec = testdir.inline_run(testpath, "--pastebin=all", '-v')
assert reprec.countoutcomes() == [1,1,1]
assert len(pastebinlist) == 1
- s = pastebinlist[0]
- for x in 'test_fail test_skip test_pass'.split():
- assert x in s
+ contents = pastebinlist[0].decode('utf-8')
+ matcher = LineMatcher(contents.splitlines())
+ matcher.fnmatch_lines([
+ '*test_pass PASSED*',
+ '*test_fail FAILED*',
+ '*test_skip SKIPPED*',
+ '*== 1 failed, 1 passed, 1 skipped in *'
+ ])
+
+ def test_non_ascii_paste_text(self, testdir):
+ """Make sure that text which contains non-ascii characters is pasted
+ correctly. See #1219.
+ """
+ testdir.makepyfile(test_unicode="""
+ # encoding: utf-8
+ def test():
+ assert '☺' == 1
+ """)
+ result = testdir.runpytest('--pastebin=all')
+ if sys.version_info[0] == 3:
+ expected_msg = "*assert '☺' == 1*"
+ else:
+ expected_msg = "*assert '\\xe2\\x98\\xba' == 1*"
+ result.stdout.fnmatch_lines([
+ expected_msg,
+ "*== 1 failed in *",
+ '*Sending information to Paste Service*',
+ ])
class TestPaste:
@@ -74,7 +101,7 @@ class TestPaste:
return calls
def test_create_new_paste(self, pastebin, mocked_urlopen):
- result = pastebin.create_new_paste('full-paste-contents')
+ result = pastebin.create_new_paste(b'full-paste-contents')
assert result == 'https://bpaste.net/show/3c0c6750bd'
assert len(mocked_urlopen) == 1
url, data = mocked_urlopen[0]