1
1
import pytest
2
+ from _pytest .pytester import Pytester
2
3
3
4
4
5
def setup_module (mod ):
5
6
mod .nose = pytest .importorskip ("nose" )
6
7
7
8
8
- def test_nose_setup (testdir ) :
9
- p = testdir .makepyfile (
9
+ def test_nose_setup (pytester : Pytester ) -> None :
10
+ p = pytester .makepyfile (
10
11
"""
11
12
values = []
12
13
from nose.tools import with_setup
@@ -22,11 +23,11 @@ def test_world():
22
23
test_hello.teardown = lambda: values.append(2)
23
24
"""
24
25
)
25
- result = testdir .runpytest (p , "-p" , "nose" )
26
+ result = pytester .runpytest (p , "-p" , "nose" )
26
27
result .assert_outcomes (passed = 2 )
27
28
28
29
29
- def test_setup_func_with_setup_decorator ():
30
+ def test_setup_func_with_setup_decorator () -> None :
30
31
from _pytest .nose import call_optional
31
32
32
33
values = []
@@ -40,7 +41,7 @@ def f(self):
40
41
assert not values
41
42
42
43
43
- def test_setup_func_not_callable ():
44
+ def test_setup_func_not_callable () -> None :
44
45
from _pytest .nose import call_optional
45
46
46
47
class A :
@@ -49,8 +50,8 @@ class A:
49
50
call_optional (A (), "f" )
50
51
51
52
52
- def test_nose_setup_func (testdir ) :
53
- p = testdir .makepyfile (
53
+ def test_nose_setup_func (pytester : Pytester ) -> None :
54
+ p = pytester .makepyfile (
54
55
"""
55
56
from nose.tools import with_setup
56
57
@@ -75,12 +76,12 @@ def test_world():
75
76
76
77
"""
77
78
)
78
- result = testdir .runpytest (p , "-p" , "nose" )
79
+ result = pytester .runpytest (p , "-p" , "nose" )
79
80
result .assert_outcomes (passed = 2 )
80
81
81
82
82
- def test_nose_setup_func_failure (testdir ) :
83
- p = testdir .makepyfile (
83
+ def test_nose_setup_func_failure (pytester : Pytester ) -> None :
84
+ p = pytester .makepyfile (
84
85
"""
85
86
from nose.tools import with_setup
86
87
@@ -99,12 +100,12 @@ def test_world():
99
100
100
101
"""
101
102
)
102
- result = testdir .runpytest (p , "-p" , "nose" )
103
+ result = pytester .runpytest (p , "-p" , "nose" )
103
104
result .stdout .fnmatch_lines (["*TypeError: <lambda>()*" ])
104
105
105
106
106
- def test_nose_setup_func_failure_2 (testdir ) :
107
- testdir .makepyfile (
107
+ def test_nose_setup_func_failure_2 (pytester : Pytester ) -> None :
108
+ pytester .makepyfile (
108
109
"""
109
110
values = []
110
111
@@ -118,13 +119,13 @@ def test_hello():
118
119
test_hello.teardown = my_teardown
119
120
"""
120
121
)
121
- reprec = testdir .inline_run ()
122
+ reprec = pytester .inline_run ()
122
123
reprec .assertoutcome (passed = 1 )
123
124
124
125
125
- def test_nose_setup_partial (testdir ) :
126
+ def test_nose_setup_partial (pytester : Pytester ) -> None :
126
127
pytest .importorskip ("functools" )
127
- p = testdir .makepyfile (
128
+ p = pytester .makepyfile (
128
129
"""
129
130
from functools import partial
130
131
@@ -153,12 +154,12 @@ def test_world():
153
154
test_hello.teardown = my_teardown_partial
154
155
"""
155
156
)
156
- result = testdir .runpytest (p , "-p" , "nose" )
157
+ result = pytester .runpytest (p , "-p" , "nose" )
157
158
result .stdout .fnmatch_lines (["*2 passed*" ])
158
159
159
160
160
- def test_module_level_setup (testdir ) :
161
- testdir .makepyfile (
161
+ def test_module_level_setup (pytester : Pytester ) -> None :
162
+ pytester .makepyfile (
162
163
"""
163
164
from nose.tools import with_setup
164
165
items = {}
@@ -184,12 +185,12 @@ def test_local_setup():
184
185
assert 1 not in items
185
186
"""
186
187
)
187
- result = testdir .runpytest ("-p" , "nose" )
188
+ result = pytester .runpytest ("-p" , "nose" )
188
189
result .stdout .fnmatch_lines (["*2 passed*" ])
189
190
190
191
191
- def test_nose_style_setup_teardown (testdir ) :
192
- testdir .makepyfile (
192
+ def test_nose_style_setup_teardown (pytester : Pytester ) -> None :
193
+ pytester .makepyfile (
193
194
"""
194
195
values = []
195
196
@@ -206,12 +207,12 @@ def test_world():
206
207
assert values == [1]
207
208
"""
208
209
)
209
- result = testdir .runpytest ("-p" , "nose" )
210
+ result = pytester .runpytest ("-p" , "nose" )
210
211
result .stdout .fnmatch_lines (["*2 passed*" ])
211
212
212
213
213
- def test_nose_setup_ordering (testdir ) :
214
- testdir .makepyfile (
214
+ def test_nose_setup_ordering (pytester : Pytester ) -> None :
215
+ pytester .makepyfile (
215
216
"""
216
217
def setup_module(mod):
217
218
mod.visited = True
@@ -223,14 +224,14 @@ def test_first(self):
223
224
pass
224
225
"""
225
226
)
226
- result = testdir .runpytest ()
227
+ result = pytester .runpytest ()
227
228
result .stdout .fnmatch_lines (["*1 passed*" ])
228
229
229
230
230
- def test_apiwrapper_problem_issue260 (testdir ) :
231
+ def test_apiwrapper_problem_issue260 (pytester : Pytester ) -> None :
231
232
# this would end up trying a call an optional teardown on the class
232
233
# for plain unittests we don't want nose behaviour
233
- testdir .makepyfile (
234
+ pytester .makepyfile (
234
235
"""
235
236
import unittest
236
237
class TestCase(unittest.TestCase):
@@ -248,14 +249,14 @@ def test_fun(self):
248
249
pass
249
250
"""
250
251
)
251
- result = testdir .runpytest ()
252
+ result = pytester .runpytest ()
252
253
result .assert_outcomes (passed = 1 )
253
254
254
255
255
- def test_setup_teardown_linking_issue265 (testdir ) :
256
+ def test_setup_teardown_linking_issue265 (pytester : Pytester ) -> None :
256
257
# we accidentally didn't integrate nose setupstate with normal setupstate
257
258
# this test ensures that won't happen again
258
- testdir .makepyfile (
259
+ pytester .makepyfile (
259
260
'''
260
261
import pytest
261
262
@@ -276,66 +277,66 @@ def teardown(self):
276
277
raise Exception("should not call teardown for skipped tests")
277
278
'''
278
279
)
279
- reprec = testdir .runpytest ()
280
+ reprec = pytester .runpytest ()
280
281
reprec .assert_outcomes (passed = 1 , skipped = 1 )
281
282
282
283
283
- def test_SkipTest_during_collection (testdir ) :
284
- p = testdir .makepyfile (
284
+ def test_SkipTest_during_collection (pytester : Pytester ) -> None :
285
+ p = pytester .makepyfile (
285
286
"""
286
287
import nose
287
288
raise nose.SkipTest("during collection")
288
289
def test_failing():
289
290
assert False
290
291
"""
291
292
)
292
- result = testdir .runpytest (p )
293
+ result = pytester .runpytest (p )
293
294
result .assert_outcomes (skipped = 1 )
294
295
295
296
296
- def test_SkipTest_in_test (testdir ) :
297
- testdir .makepyfile (
297
+ def test_SkipTest_in_test (pytester : Pytester ) -> None :
298
+ pytester .makepyfile (
298
299
"""
299
300
import nose
300
301
301
302
def test_skipping():
302
303
raise nose.SkipTest("in test")
303
304
"""
304
305
)
305
- reprec = testdir .inline_run ()
306
+ reprec = pytester .inline_run ()
306
307
reprec .assertoutcome (skipped = 1 )
307
308
308
309
309
- def test_istest_function_decorator (testdir ) :
310
- p = testdir .makepyfile (
310
+ def test_istest_function_decorator (pytester : Pytester ) -> None :
311
+ p = pytester .makepyfile (
311
312
"""
312
313
import nose.tools
313
314
@nose.tools.istest
314
315
def not_test_prefix():
315
316
pass
316
317
"""
317
318
)
318
- result = testdir .runpytest (p )
319
+ result = pytester .runpytest (p )
319
320
result .assert_outcomes (passed = 1 )
320
321
321
322
322
- def test_nottest_function_decorator (testdir ) :
323
- testdir .makepyfile (
323
+ def test_nottest_function_decorator (pytester : Pytester ) -> None :
324
+ pytester .makepyfile (
324
325
"""
325
326
import nose.tools
326
327
@nose.tools.nottest
327
328
def test_prefix():
328
329
pass
329
330
"""
330
331
)
331
- reprec = testdir .inline_run ()
332
+ reprec = pytester .inline_run ()
332
333
assert not reprec .getfailedcollections ()
333
334
calls = reprec .getreports ("pytest_runtest_logreport" )
334
335
assert not calls
335
336
336
337
337
- def test_istest_class_decorator (testdir ) :
338
- p = testdir .makepyfile (
338
+ def test_istest_class_decorator (pytester : Pytester ) -> None :
339
+ p = pytester .makepyfile (
339
340
"""
340
341
import nose.tools
341
342
@nose.tools.istest
@@ -344,12 +345,12 @@ def test_method(self):
344
345
pass
345
346
"""
346
347
)
347
- result = testdir .runpytest (p )
348
+ result = pytester .runpytest (p )
348
349
result .assert_outcomes (passed = 1 )
349
350
350
351
351
- def test_nottest_class_decorator (testdir ) :
352
- testdir .makepyfile (
352
+ def test_nottest_class_decorator (pytester : Pytester ) -> None :
353
+ pytester .makepyfile (
353
354
"""
354
355
import nose.tools
355
356
@nose.tools.nottest
@@ -358,27 +359,27 @@ def test_method(self):
358
359
pass
359
360
"""
360
361
)
361
- reprec = testdir .inline_run ()
362
+ reprec = pytester .inline_run ()
362
363
assert not reprec .getfailedcollections ()
363
364
calls = reprec .getreports ("pytest_runtest_logreport" )
364
365
assert not calls
365
366
366
367
367
- def test_skip_test_with_unicode (testdir ) :
368
- testdir .makepyfile (
368
+ def test_skip_test_with_unicode (pytester : Pytester ) -> None :
369
+ pytester .makepyfile (
369
370
"""\
370
371
import unittest
371
372
class TestClass():
372
373
def test_io(self):
373
374
raise unittest.SkipTest('😊')
374
375
"""
375
376
)
376
- result = testdir .runpytest ()
377
+ result = pytester .runpytest ()
377
378
result .stdout .fnmatch_lines (["* 1 skipped *" ])
378
379
379
380
380
- def test_raises (testdir ) :
381
- testdir .makepyfile (
381
+ def test_raises (pytester : Pytester ) -> None :
382
+ pytester .makepyfile (
382
383
"""
383
384
from nose.tools import raises
384
385
@@ -395,7 +396,7 @@ def test_raises_baseexception_caught():
395
396
raise BaseException
396
397
"""
397
398
)
398
- result = testdir .runpytest ("-vv" )
399
+ result = pytester .runpytest ("-vv" )
399
400
result .stdout .fnmatch_lines (
400
401
[
401
402
"test_raises.py::test_raises_runtimeerror PASSED*" ,
0 commit comments