2
2
from typing import List
3
3
4
4
import pytest
5
+ from _pytest .pytester import Pytester
5
6
6
7
7
- def test_module_and_function_setup (testdir ) :
8
- reprec = testdir .inline_runsource (
8
+ def test_module_and_function_setup (pytester : Pytester ) -> None :
9
+ reprec = pytester .inline_runsource (
9
10
"""
10
11
modlevel = []
11
12
def setup_module(module):
@@ -37,8 +38,8 @@ def test_module(self):
37
38
assert rep .passed
38
39
39
40
40
- def test_module_setup_failure_no_teardown (testdir ) :
41
- reprec = testdir .inline_runsource (
41
+ def test_module_setup_failure_no_teardown (pytester : Pytester ) -> None :
42
+ reprec = pytester .inline_runsource (
42
43
"""
43
44
values = []
44
45
def setup_module(module):
@@ -57,8 +58,8 @@ def teardown_module(module):
57
58
assert calls [0 ].item .module .values == [1 ]
58
59
59
60
60
- def test_setup_function_failure_no_teardown (testdir ) :
61
- reprec = testdir .inline_runsource (
61
+ def test_setup_function_failure_no_teardown (pytester : Pytester ) -> None :
62
+ reprec = pytester .inline_runsource (
62
63
"""
63
64
modlevel = []
64
65
def setup_function(function):
@@ -76,8 +77,8 @@ def test_func():
76
77
assert calls [0 ].item .module .modlevel == [1 ]
77
78
78
79
79
- def test_class_setup (testdir ) :
80
- reprec = testdir .inline_runsource (
80
+ def test_class_setup (pytester : Pytester ) -> None :
81
+ reprec = pytester .inline_runsource (
81
82
"""
82
83
class TestSimpleClassSetup(object):
83
84
clslevel = []
@@ -102,8 +103,8 @@ def test_cleanup():
102
103
reprec .assertoutcome (passed = 1 + 2 + 1 )
103
104
104
105
105
- def test_class_setup_failure_no_teardown (testdir ) :
106
- reprec = testdir .inline_runsource (
106
+ def test_class_setup_failure_no_teardown (pytester : Pytester ) -> None :
107
+ reprec = pytester .inline_runsource (
107
108
"""
108
109
class TestSimpleClassSetup(object):
109
110
clslevel = []
@@ -123,8 +124,8 @@ def test_cleanup():
123
124
reprec .assertoutcome (failed = 1 , passed = 1 )
124
125
125
126
126
- def test_method_setup (testdir ) :
127
- reprec = testdir .inline_runsource (
127
+ def test_method_setup (pytester : Pytester ) -> None :
128
+ reprec = pytester .inline_runsource (
128
129
"""
129
130
class TestSetupMethod(object):
130
131
def setup_method(self, meth):
@@ -142,8 +143,8 @@ def test_other(self):
142
143
reprec .assertoutcome (passed = 2 )
143
144
144
145
145
- def test_method_setup_failure_no_teardown (testdir ) :
146
- reprec = testdir .inline_runsource (
146
+ def test_method_setup_failure_no_teardown (pytester : Pytester ) -> None :
147
+ reprec = pytester .inline_runsource (
147
148
"""
148
149
class TestMethodSetup(object):
149
150
clslevel = []
@@ -164,8 +165,8 @@ def test_cleanup():
164
165
reprec .assertoutcome (failed = 1 , passed = 1 )
165
166
166
167
167
- def test_method_setup_uses_fresh_instances (testdir ) :
168
- reprec = testdir .inline_runsource (
168
+ def test_method_setup_uses_fresh_instances (pytester : Pytester ) -> None :
169
+ reprec = pytester .inline_runsource (
169
170
"""
170
171
class TestSelfState1(object):
171
172
memory = []
@@ -179,8 +180,8 @@ def test_afterhello(self):
179
180
reprec .assertoutcome (passed = 2 , failed = 0 )
180
181
181
182
182
- def test_setup_that_skips_calledagain (testdir ) :
183
- p = testdir .makepyfile (
183
+ def test_setup_that_skips_calledagain (pytester : Pytester ) -> None :
184
+ p = pytester .makepyfile (
184
185
"""
185
186
import pytest
186
187
def setup_module(mod):
@@ -191,12 +192,12 @@ def test_function2():
191
192
pass
192
193
"""
193
194
)
194
- reprec = testdir .inline_run (p )
195
+ reprec = pytester .inline_run (p )
195
196
reprec .assertoutcome (skipped = 2 )
196
197
197
198
198
- def test_setup_fails_again_on_all_tests (testdir ) :
199
- p = testdir .makepyfile (
199
+ def test_setup_fails_again_on_all_tests (pytester : Pytester ) -> None :
200
+ p = pytester .makepyfile (
200
201
"""
201
202
import pytest
202
203
def setup_module(mod):
@@ -207,12 +208,12 @@ def test_function2():
207
208
pass
208
209
"""
209
210
)
210
- reprec = testdir .inline_run (p )
211
+ reprec = pytester .inline_run (p )
211
212
reprec .assertoutcome (failed = 2 )
212
213
213
214
214
- def test_setup_funcarg_setup_when_outer_scope_fails (testdir ) :
215
- p = testdir .makepyfile (
215
+ def test_setup_funcarg_setup_when_outer_scope_fails (pytester : Pytester ) -> None :
216
+ p = pytester .makepyfile (
216
217
"""
217
218
import pytest
218
219
def setup_module(mod):
@@ -226,7 +227,7 @@ def test_function2(hello):
226
227
pass
227
228
"""
228
229
)
229
- result = testdir .runpytest (p )
230
+ result = pytester .runpytest (p )
230
231
result .stdout .fnmatch_lines (
231
232
[
232
233
"*function1*" ,
@@ -241,7 +242,7 @@ def test_function2(hello):
241
242
242
243
@pytest .mark .parametrize ("arg" , ["" , "arg" ])
243
244
def test_setup_teardown_function_level_with_optional_argument (
244
- testdir , monkeypatch , arg : str ,
245
+ pytester : Pytester , monkeypatch , arg : str ,
245
246
) -> None :
246
247
"""Parameter to setup/teardown xunit-style functions parameter is now optional (#1728)."""
247
248
import sys
@@ -250,7 +251,7 @@ def test_setup_teardown_function_level_with_optional_argument(
250
251
monkeypatch .setattr (
251
252
sys , "trace_setups_teardowns" , trace_setups_teardowns , raising = False
252
253
)
253
- p = testdir .makepyfile (
254
+ p = pytester .makepyfile (
254
255
"""
255
256
import pytest
256
257
import sys
@@ -276,7 +277,7 @@ def test_method_2(self): pass
276
277
arg = arg
277
278
)
278
279
)
279
- result = testdir .inline_run (p )
280
+ result = pytester .inline_run (p )
280
281
result .assertoutcome (passed = 4 )
281
282
282
283
expected = [
0 commit comments