3
3
from typing import Union
4
4
5
5
import pytest
6
+ from _pytest .monkeypatch import MonkeyPatch
7
+ from _pytest .pytester import Pytester
6
8
7
9
8
10
class TestPasteCapture :
@@ -13,28 +15,28 @@ def pastebinlist(self, monkeypatch, request) -> List[Union[str, bytes]]:
13
15
monkeypatch .setattr (plugin , "create_new_paste" , pastebinlist .append )
14
16
return pastebinlist
15
17
16
- def test_failed (self , testdir , pastebinlist ):
17
- testpath = testdir .makepyfile (
18
+ def test_failed (self , pytester : Pytester , pastebinlist ) -> None :
19
+ testpath = pytester .makepyfile (
18
20
"""
19
21
import pytest
20
- def test_pass():
22
+ def test_pass() -> None :
21
23
pass
22
24
def test_fail():
23
25
assert 0
24
26
def test_skip():
25
27
pytest.skip("")
26
28
"""
27
29
)
28
- reprec = testdir .inline_run (testpath , "--pastebin=failed" )
30
+ reprec = pytester .inline_run (testpath , "--pastebin=failed" )
29
31
assert len (pastebinlist ) == 1
30
32
s = pastebinlist [0 ]
31
33
assert s .find ("def test_fail" ) != - 1
32
34
assert reprec .countoutcomes () == [1 , 1 , 1 ]
33
35
34
- def test_all (self , testdir , pastebinlist ):
36
+ def test_all (self , pytester : Pytester , pastebinlist ) -> None :
35
37
from _pytest .pytester import LineMatcher
36
38
37
- testpath = testdir .makepyfile (
39
+ testpath = pytester .makepyfile (
38
40
"""
39
41
import pytest
40
42
def test_pass():
@@ -45,7 +47,7 @@ def test_skip():
45
47
pytest.skip("")
46
48
"""
47
49
)
48
- reprec = testdir .inline_run (testpath , "--pastebin=all" , "-v" )
50
+ reprec = pytester .inline_run (testpath , "--pastebin=all" , "-v" )
49
51
assert reprec .countoutcomes () == [1 , 1 , 1 ]
50
52
assert len (pastebinlist ) == 1
51
53
contents = pastebinlist [0 ].decode ("utf-8" )
@@ -59,17 +61,17 @@ def test_skip():
59
61
]
60
62
)
61
63
62
- def test_non_ascii_paste_text (self , testdir , pastebinlist ):
64
+ def test_non_ascii_paste_text (self , pytester : Pytester , pastebinlist ) -> None :
63
65
"""Make sure that text which contains non-ascii characters is pasted
64
66
correctly. See #1219.
65
67
"""
66
- testdir .makepyfile (
68
+ pytester .makepyfile (
67
69
test_unicode = """\
68
70
def test():
69
71
assert '☺' == 1
70
72
"""
71
73
)
72
- result = testdir .runpytest ("--pastebin=all" )
74
+ result = pytester .runpytest ("--pastebin=all" )
73
75
expected_msg = "*assert '☺' == 1*"
74
76
result .stdout .fnmatch_lines (
75
77
[
@@ -87,7 +89,7 @@ def pastebin(self, request):
87
89
return request .config .pluginmanager .getplugin ("pastebin" )
88
90
89
91
@pytest .fixture
90
- def mocked_urlopen_fail (self , monkeypatch ):
92
+ def mocked_urlopen_fail (self , monkeypatch : MonkeyPatch ):
91
93
"""Monkeypatch the actual urlopen call to emulate a HTTP Error 400."""
92
94
calls = []
93
95
@@ -102,7 +104,7 @@ def mocked(url, data):
102
104
return calls
103
105
104
106
@pytest .fixture
105
- def mocked_urlopen_invalid (self , monkeypatch ):
107
+ def mocked_urlopen_invalid (self , monkeypatch : MonkeyPatch ):
106
108
"""Monkeypatch the actual urlopen calls done by the internal plugin
107
109
function that connects to bpaste service, but return a url in an
108
110
unexpected format."""
@@ -124,7 +126,7 @@ def read(self):
124
126
return calls
125
127
126
128
@pytest .fixture
127
- def mocked_urlopen (self , monkeypatch ):
129
+ def mocked_urlopen (self , monkeypatch : MonkeyPatch ):
128
130
"""Monkeypatch the actual urlopen calls done by the internal plugin
129
131
function that connects to bpaste service."""
130
132
calls = []
@@ -144,20 +146,20 @@ def read(self):
144
146
monkeypatch .setattr (urllib .request , "urlopen" , mocked )
145
147
return calls
146
148
147
- def test_pastebin_invalid_url (self , pastebin , mocked_urlopen_invalid ):
149
+ def test_pastebin_invalid_url (self , pastebin , mocked_urlopen_invalid ) -> None :
148
150
result = pastebin .create_new_paste (b"full-paste-contents" )
149
151
assert (
150
152
result
151
153
== "bad response: invalid format ('View <a href=\" /invalid/3c0c6750bd\" >raw</a>.')"
152
154
)
153
155
assert len (mocked_urlopen_invalid ) == 1
154
156
155
- def test_pastebin_http_error (self , pastebin , mocked_urlopen_fail ):
157
+ def test_pastebin_http_error (self , pastebin , mocked_urlopen_fail ) -> None :
156
158
result = pastebin .create_new_paste (b"full-paste-contents" )
157
159
assert result == "bad response: HTTP Error 400: Bad request"
158
160
assert len (mocked_urlopen_fail ) == 1
159
161
160
- def test_create_new_paste (self , pastebin , mocked_urlopen ):
162
+ def test_create_new_paste (self , pastebin , mocked_urlopen ) -> None :
161
163
result = pastebin .create_new_paste (b"full-paste-contents" )
162
164
assert result == "https://bpaste.net/show/3c0c6750bd"
163
165
assert len (mocked_urlopen ) == 1
@@ -169,7 +171,7 @@ def test_create_new_paste(self, pastebin, mocked_urlopen):
169
171
assert "code=full-paste-contents" in data .decode ()
170
172
assert "expiry=1week" in data .decode ()
171
173
172
- def test_create_new_paste_failure (self , pastebin , monkeypatch ) :
174
+ def test_create_new_paste_failure (self , pastebin , monkeypatch : MonkeyPatch ) -> None :
173
175
import io
174
176
import urllib .request
175
177
0 commit comments