2
2
3
3
import pytest
4
4
from _pytest .config import ExitCode
5
+ from _pytest .pytester import Pytester
5
6
6
7
7
8
@pytest .fixture (params = ["--setup-only" , "--setup-plan" , "--setup-show" ], scope = "module" )
8
9
def mode (request ):
9
10
return request .param
10
11
11
12
12
- def test_show_only_active_fixtures (testdir , mode , dummy_yaml_custom_test ):
13
- testdir .makepyfile (
13
+ def test_show_only_active_fixtures (
14
+ pytester : Pytester , mode , dummy_yaml_custom_test
15
+ ) -> None :
16
+ pytester .makepyfile (
14
17
'''
15
18
import pytest
16
19
@pytest.fixture
@@ -24,7 +27,7 @@ def test_arg1(arg1):
24
27
'''
25
28
)
26
29
27
- result = testdir .runpytest (mode )
30
+ result = pytester .runpytest (mode )
28
31
assert result .ret == 0
29
32
30
33
result .stdout .fnmatch_lines (
@@ -33,8 +36,8 @@ def test_arg1(arg1):
33
36
result .stdout .no_fnmatch_line ("*_arg0*" )
34
37
35
38
36
- def test_show_different_scopes (testdir , mode ):
37
- p = testdir .makepyfile (
39
+ def test_show_different_scopes (pytester : Pytester , mode ) -> None :
40
+ p = pytester .makepyfile (
38
41
'''
39
42
import pytest
40
43
@pytest.fixture
@@ -48,7 +51,7 @@ def test_arg1(arg_session, arg_function):
48
51
'''
49
52
)
50
53
51
- result = testdir .runpytest (mode , p )
54
+ result = pytester .runpytest (mode , p )
52
55
assert result .ret == 0
53
56
54
57
result .stdout .fnmatch_lines (
@@ -62,16 +65,16 @@ def test_arg1(arg_session, arg_function):
62
65
)
63
66
64
67
65
- def test_show_nested_fixtures (testdir , mode ):
66
- testdir .makeconftest (
68
+ def test_show_nested_fixtures (pytester : Pytester , mode ) -> None :
69
+ pytester .makeconftest (
67
70
'''
68
71
import pytest
69
72
@pytest.fixture(scope='session')
70
73
def arg_same():
71
74
"""session scoped fixture"""
72
75
'''
73
76
)
74
- p = testdir .makepyfile (
77
+ p = pytester .makepyfile (
75
78
'''
76
79
import pytest
77
80
@pytest.fixture(scope='function')
@@ -82,7 +85,7 @@ def test_arg1(arg_same):
82
85
'''
83
86
)
84
87
85
- result = testdir .runpytest (mode , p )
88
+ result = pytester .runpytest (mode , p )
86
89
assert result .ret == 0
87
90
88
91
result .stdout .fnmatch_lines (
@@ -96,8 +99,8 @@ def test_arg1(arg_same):
96
99
)
97
100
98
101
99
- def test_show_fixtures_with_autouse (testdir , mode ):
100
- p = testdir .makepyfile (
102
+ def test_show_fixtures_with_autouse (pytester : Pytester , mode ) -> None :
103
+ p = pytester .makepyfile (
101
104
'''
102
105
import pytest
103
106
@pytest.fixture
@@ -111,7 +114,7 @@ def test_arg1(arg_function):
111
114
'''
112
115
)
113
116
114
- result = testdir .runpytest (mode , p )
117
+ result = pytester .runpytest (mode , p )
115
118
assert result .ret == 0
116
119
117
120
result .stdout .fnmatch_lines (
@@ -123,16 +126,16 @@ def test_arg1(arg_function):
123
126
)
124
127
125
128
126
- def test_show_fixtures_with_parameters (testdir , mode ):
127
- testdir .makeconftest (
129
+ def test_show_fixtures_with_parameters (pytester : Pytester , mode ) -> None :
130
+ pytester .makeconftest (
128
131
'''
129
132
import pytest
130
133
@pytest.fixture(scope='session', params=['foo', 'bar'])
131
134
def arg_same():
132
135
"""session scoped fixture"""
133
136
'''
134
137
)
135
- p = testdir .makepyfile (
138
+ p = pytester .makepyfile (
136
139
'''
137
140
import pytest
138
141
@pytest.fixture(scope='function')
@@ -143,7 +146,7 @@ def test_arg1(arg_other):
143
146
'''
144
147
)
145
148
146
- result = testdir .runpytest (mode , p )
149
+ result = pytester .runpytest (mode , p )
147
150
assert result .ret == 0
148
151
149
152
result .stdout .fnmatch_lines (
@@ -156,8 +159,8 @@ def test_arg1(arg_other):
156
159
)
157
160
158
161
159
- def test_show_fixtures_with_parameter_ids (testdir , mode ):
160
- testdir .makeconftest (
162
+ def test_show_fixtures_with_parameter_ids (pytester : Pytester , mode ) -> None :
163
+ pytester .makeconftest (
161
164
'''
162
165
import pytest
163
166
@pytest.fixture(
@@ -166,7 +169,7 @@ def arg_same():
166
169
"""session scoped fixture"""
167
170
'''
168
171
)
169
- p = testdir .makepyfile (
172
+ p = pytester .makepyfile (
170
173
'''
171
174
import pytest
172
175
@pytest.fixture(scope='function')
@@ -177,16 +180,16 @@ def test_arg1(arg_other):
177
180
'''
178
181
)
179
182
180
- result = testdir .runpytest (mode , p )
183
+ result = pytester .runpytest (mode , p )
181
184
assert result .ret == 0
182
185
183
186
result .stdout .fnmatch_lines (
184
187
["SETUP S arg_same?'spam'?" , "SETUP S arg_same?'ham'?" ]
185
188
)
186
189
187
190
188
- def test_show_fixtures_with_parameter_ids_function (testdir , mode ):
189
- p = testdir .makepyfile (
191
+ def test_show_fixtures_with_parameter_ids_function (pytester : Pytester , mode ) -> None :
192
+ p = pytester .makepyfile (
190
193
"""
191
194
import pytest
192
195
@pytest.fixture(params=['foo', 'bar'], ids=lambda p: p.upper())
@@ -197,16 +200,16 @@ def test_foobar(foobar):
197
200
"""
198
201
)
199
202
200
- result = testdir .runpytest (mode , p )
203
+ result = pytester .runpytest (mode , p )
201
204
assert result .ret == 0
202
205
203
206
result .stdout .fnmatch_lines (
204
207
["*SETUP F foobar?'FOO'?" , "*SETUP F foobar?'BAR'?" ]
205
208
)
206
209
207
210
208
- def test_dynamic_fixture_request (testdir ) :
209
- p = testdir .makepyfile (
211
+ def test_dynamic_fixture_request (pytester : Pytester ) -> None :
212
+ p = pytester .makepyfile (
210
213
"""
211
214
import pytest
212
215
@pytest.fixture()
@@ -220,7 +223,7 @@ def test_dyn(dependent_fixture):
220
223
"""
221
224
)
222
225
223
- result = testdir .runpytest ("--setup-only" , p )
226
+ result = pytester .runpytest ("--setup-only" , p )
224
227
assert result .ret == 0
225
228
226
229
result .stdout .fnmatch_lines (
@@ -231,8 +234,8 @@ def test_dyn(dependent_fixture):
231
234
)
232
235
233
236
234
- def test_capturing (testdir ) :
235
- p = testdir .makepyfile (
237
+ def test_capturing (pytester : Pytester ) -> None :
238
+ p = pytester .makepyfile (
236
239
"""
237
240
import pytest, sys
238
241
@pytest.fixture()
@@ -247,15 +250,15 @@ def test_capturing(two):
247
250
"""
248
251
)
249
252
250
- result = testdir .runpytest ("--setup-only" , p )
253
+ result = pytester .runpytest ("--setup-only" , p )
251
254
result .stdout .fnmatch_lines (
252
255
["this should be captured" , "this should also be captured" ]
253
256
)
254
257
255
258
256
- def test_show_fixtures_and_execute_test (testdir ) :
259
+ def test_show_fixtures_and_execute_test (pytester : Pytester ) -> None :
257
260
"""Verify that setups are shown and tests are executed."""
258
- p = testdir .makepyfile (
261
+ p = pytester .makepyfile (
259
262
"""
260
263
import pytest
261
264
@pytest.fixture
@@ -266,16 +269,16 @@ def test_arg(arg):
266
269
"""
267
270
)
268
271
269
- result = testdir .runpytest ("--setup-show" , p )
272
+ result = pytester .runpytest ("--setup-show" , p )
270
273
assert result .ret == 1
271
274
272
275
result .stdout .fnmatch_lines (
273
276
["*SETUP F arg*" , "*test_arg (fixtures used: arg)F*" , "*TEARDOWN F arg*" ]
274
277
)
275
278
276
279
277
- def test_setup_show_with_KeyboardInterrupt_in_test (testdir ) :
278
- p = testdir .makepyfile (
280
+ def test_setup_show_with_KeyboardInterrupt_in_test (pytester : Pytester ) -> None :
281
+ p = pytester .makepyfile (
279
282
"""
280
283
import pytest
281
284
@pytest.fixture
@@ -285,7 +288,7 @@ def test_arg(arg):
285
288
raise KeyboardInterrupt()
286
289
"""
287
290
)
288
- result = testdir .runpytest ("--setup-show" , p , no_reraise_ctrlc = True )
291
+ result = pytester .runpytest ("--setup-show" , p , no_reraise_ctrlc = True )
289
292
result .stdout .fnmatch_lines (
290
293
[
291
294
"*SETUP F arg*" ,
@@ -298,9 +301,9 @@ def test_arg(arg):
298
301
assert result .ret == ExitCode .INTERRUPTED
299
302
300
303
301
- def test_show_fixture_action_with_bytes (testdir ) :
304
+ def test_show_fixture_action_with_bytes (pytester : Pytester ) -> None :
302
305
# Issue 7126, BytesWarning when using --setup-show with bytes parameter
303
- test_file = testdir .makepyfile (
306
+ test_file = pytester .makepyfile (
304
307
"""
305
308
import pytest
306
309
@@ -309,7 +312,7 @@ def test_data(data):
309
312
pass
310
313
"""
311
314
)
312
- result = testdir .run (
315
+ result = pytester .run (
313
316
sys .executable , "-bb" , "-m" , "pytest" , "--setup-show" , str (test_file )
314
317
)
315
318
assert result .ret == 0
0 commit comments