1
+ # encoding: utf-8
1
2
import sys
2
3
import pytest
3
4
@@ -27,6 +28,7 @@ def test_skip():
27
28
assert reprec .countoutcomes () == [1 ,1 ,1 ]
28
29
29
30
def test_all (self , testdir , pastebinlist ):
31
+ from _pytest .pytester import LineMatcher
30
32
testpath = testdir .makepyfile ("""
31
33
import pytest
32
34
def test_pass():
@@ -39,9 +41,34 @@ def test_skip():
39
41
reprec = testdir .inline_run (testpath , "--pastebin=all" , '-v' )
40
42
assert reprec .countoutcomes () == [1 ,1 ,1 ]
41
43
assert len (pastebinlist ) == 1
42
- s = pastebinlist [0 ]
43
- for x in 'test_fail test_skip test_pass' .split ():
44
- assert x in s
44
+ contents = pastebinlist [0 ].decode ('utf-8' )
45
+ matcher = LineMatcher (contents .splitlines ())
46
+ matcher .fnmatch_lines ([
47
+ '*test_pass PASSED*' ,
48
+ '*test_fail FAILED*' ,
49
+ '*test_skip SKIPPED*' ,
50
+ '*== 1 failed, 1 passed, 1 skipped in *'
51
+ ])
52
+
53
+ def test_non_ascii_paste_text (self , testdir ):
54
+ """Make sure that text which contains non-ascii characters is pasted
55
+ correctly. See #1219.
56
+ """
57
+ testdir .makepyfile (test_unicode = """
58
+ # encoding: utf-8
59
+ def test():
60
+ assert '☺' == 1
61
+ """ )
62
+ result = testdir .runpytest ('--pastebin=all' )
63
+ if sys .version_info [0 ] == 3 :
64
+ expected_msg = "*assert '☺' == 1*"
65
+ else :
66
+ expected_msg = "*assert '\\ xe2\\ x98\\ xba' == 1*"
67
+ result .stdout .fnmatch_lines ([
68
+ expected_msg ,
69
+ "*== 1 failed in *" ,
70
+ '*Sending information to Paste Service*' ,
71
+ ])
45
72
46
73
47
74
class TestPaste :
@@ -74,7 +101,7 @@ def read(self):
74
101
return calls
75
102
76
103
def test_create_new_paste (self , pastebin , mocked_urlopen ):
77
- result = pastebin .create_new_paste ('full-paste-contents' )
104
+ result = pastebin .create_new_paste (b 'full-paste-contents' )
78
105
assert result == 'https://bpaste.net/show/3c0c6750bd'
79
106
assert len (mocked_urlopen ) == 1
80
107
url , data = mocked_urlopen [0 ]
0 commit comments