Skip to content

Commit 460b51d

Browse files
authoredOct 29, 2020
Migrate test_setuponly.py from testdir to pytester (#7959)
1 parent efe470b commit 460b51d

File tree

1 file changed

+42
-39
lines changed

1 file changed

+42
-39
lines changed
 

‎testing/test_setuponly.py

+42-39
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
import pytest
44
from _pytest.config import ExitCode
5+
from _pytest.pytester import Pytester
56

67

78
@pytest.fixture(params=["--setup-only", "--setup-plan", "--setup-show"], scope="module")
89
def mode(request):
910
return request.param
1011

1112

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(
1417
'''
1518
import pytest
1619
@pytest.fixture
@@ -24,7 +27,7 @@ def test_arg1(arg1):
2427
'''
2528
)
2629

27-
result = testdir.runpytest(mode)
30+
result = pytester.runpytest(mode)
2831
assert result.ret == 0
2932

3033
result.stdout.fnmatch_lines(
@@ -33,8 +36,8 @@ def test_arg1(arg1):
3336
result.stdout.no_fnmatch_line("*_arg0*")
3437

3538

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(
3841
'''
3942
import pytest
4043
@pytest.fixture
@@ -48,7 +51,7 @@ def test_arg1(arg_session, arg_function):
4851
'''
4952
)
5053

51-
result = testdir.runpytest(mode, p)
54+
result = pytester.runpytest(mode, p)
5255
assert result.ret == 0
5356

5457
result.stdout.fnmatch_lines(
@@ -62,16 +65,16 @@ def test_arg1(arg_session, arg_function):
6265
)
6366

6467

65-
def test_show_nested_fixtures(testdir, mode):
66-
testdir.makeconftest(
68+
def test_show_nested_fixtures(pytester: Pytester, mode) -> None:
69+
pytester.makeconftest(
6770
'''
6871
import pytest
6972
@pytest.fixture(scope='session')
7073
def arg_same():
7174
"""session scoped fixture"""
7275
'''
7376
)
74-
p = testdir.makepyfile(
77+
p = pytester.makepyfile(
7578
'''
7679
import pytest
7780
@pytest.fixture(scope='function')
@@ -82,7 +85,7 @@ def test_arg1(arg_same):
8285
'''
8386
)
8487

85-
result = testdir.runpytest(mode, p)
88+
result = pytester.runpytest(mode, p)
8689
assert result.ret == 0
8790

8891
result.stdout.fnmatch_lines(
@@ -96,8 +99,8 @@ def test_arg1(arg_same):
9699
)
97100

98101

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(
101104
'''
102105
import pytest
103106
@pytest.fixture
@@ -111,7 +114,7 @@ def test_arg1(arg_function):
111114
'''
112115
)
113116

114-
result = testdir.runpytest(mode, p)
117+
result = pytester.runpytest(mode, p)
115118
assert result.ret == 0
116119

117120
result.stdout.fnmatch_lines(
@@ -123,16 +126,16 @@ def test_arg1(arg_function):
123126
)
124127

125128

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(
128131
'''
129132
import pytest
130133
@pytest.fixture(scope='session', params=['foo', 'bar'])
131134
def arg_same():
132135
"""session scoped fixture"""
133136
'''
134137
)
135-
p = testdir.makepyfile(
138+
p = pytester.makepyfile(
136139
'''
137140
import pytest
138141
@pytest.fixture(scope='function')
@@ -143,7 +146,7 @@ def test_arg1(arg_other):
143146
'''
144147
)
145148

146-
result = testdir.runpytest(mode, p)
149+
result = pytester.runpytest(mode, p)
147150
assert result.ret == 0
148151

149152
result.stdout.fnmatch_lines(
@@ -156,8 +159,8 @@ def test_arg1(arg_other):
156159
)
157160

158161

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(
161164
'''
162165
import pytest
163166
@pytest.fixture(
@@ -166,7 +169,7 @@ def arg_same():
166169
"""session scoped fixture"""
167170
'''
168171
)
169-
p = testdir.makepyfile(
172+
p = pytester.makepyfile(
170173
'''
171174
import pytest
172175
@pytest.fixture(scope='function')
@@ -177,16 +180,16 @@ def test_arg1(arg_other):
177180
'''
178181
)
179182

180-
result = testdir.runpytest(mode, p)
183+
result = pytester.runpytest(mode, p)
181184
assert result.ret == 0
182185

183186
result.stdout.fnmatch_lines(
184187
["SETUP S arg_same?'spam'?", "SETUP S arg_same?'ham'?"]
185188
)
186189

187190

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(
190193
"""
191194
import pytest
192195
@pytest.fixture(params=['foo', 'bar'], ids=lambda p: p.upper())
@@ -197,16 +200,16 @@ def test_foobar(foobar):
197200
"""
198201
)
199202

200-
result = testdir.runpytest(mode, p)
203+
result = pytester.runpytest(mode, p)
201204
assert result.ret == 0
202205

203206
result.stdout.fnmatch_lines(
204207
["*SETUP F foobar?'FOO'?", "*SETUP F foobar?'BAR'?"]
205208
)
206209

207210

208-
def test_dynamic_fixture_request(testdir):
209-
p = testdir.makepyfile(
211+
def test_dynamic_fixture_request(pytester: Pytester) -> None:
212+
p = pytester.makepyfile(
210213
"""
211214
import pytest
212215
@pytest.fixture()
@@ -220,7 +223,7 @@ def test_dyn(dependent_fixture):
220223
"""
221224
)
222225

223-
result = testdir.runpytest("--setup-only", p)
226+
result = pytester.runpytest("--setup-only", p)
224227
assert result.ret == 0
225228

226229
result.stdout.fnmatch_lines(
@@ -231,8 +234,8 @@ def test_dyn(dependent_fixture):
231234
)
232235

233236

234-
def test_capturing(testdir):
235-
p = testdir.makepyfile(
237+
def test_capturing(pytester: Pytester) -> None:
238+
p = pytester.makepyfile(
236239
"""
237240
import pytest, sys
238241
@pytest.fixture()
@@ -247,15 +250,15 @@ def test_capturing(two):
247250
"""
248251
)
249252

250-
result = testdir.runpytest("--setup-only", p)
253+
result = pytester.runpytest("--setup-only", p)
251254
result.stdout.fnmatch_lines(
252255
["this should be captured", "this should also be captured"]
253256
)
254257

255258

256-
def test_show_fixtures_and_execute_test(testdir):
259+
def test_show_fixtures_and_execute_test(pytester: Pytester) -> None:
257260
"""Verify that setups are shown and tests are executed."""
258-
p = testdir.makepyfile(
261+
p = pytester.makepyfile(
259262
"""
260263
import pytest
261264
@pytest.fixture
@@ -266,16 +269,16 @@ def test_arg(arg):
266269
"""
267270
)
268271

269-
result = testdir.runpytest("--setup-show", p)
272+
result = pytester.runpytest("--setup-show", p)
270273
assert result.ret == 1
271274

272275
result.stdout.fnmatch_lines(
273276
["*SETUP F arg*", "*test_arg (fixtures used: arg)F*", "*TEARDOWN F arg*"]
274277
)
275278

276279

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(
279282
"""
280283
import pytest
281284
@pytest.fixture
@@ -285,7 +288,7 @@ def test_arg(arg):
285288
raise KeyboardInterrupt()
286289
"""
287290
)
288-
result = testdir.runpytest("--setup-show", p, no_reraise_ctrlc=True)
291+
result = pytester.runpytest("--setup-show", p, no_reraise_ctrlc=True)
289292
result.stdout.fnmatch_lines(
290293
[
291294
"*SETUP F arg*",
@@ -298,9 +301,9 @@ def test_arg(arg):
298301
assert result.ret == ExitCode.INTERRUPTED
299302

300303

301-
def test_show_fixture_action_with_bytes(testdir):
304+
def test_show_fixture_action_with_bytes(pytester: Pytester) -> None:
302305
# Issue 7126, BytesWarning when using --setup-show with bytes parameter
303-
test_file = testdir.makepyfile(
306+
test_file = pytester.makepyfile(
304307
"""
305308
import pytest
306309
@@ -309,7 +312,7 @@ def test_data(data):
309312
pass
310313
"""
311314
)
312-
result = testdir.run(
315+
result = pytester.run(
313316
sys.executable, "-bb", "-m", "pytest", "--setup-show", str(test_file)
314317
)
315318
assert result.ret == 0

0 commit comments

Comments
 (0)
Please sign in to comment.