Skip to content

Commit d4c81ff

Browse files
committed
Migrate test_nose.py from testdir to pytester
1 parent d1cb9de commit d4c81ff

File tree

1 file changed

+57
-56
lines changed

1 file changed

+57
-56
lines changed

testing/test_nose.py

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import pytest
2+
from _pytest.pytester import Pytester
23

34

45
def setup_module(mod):
56
mod.nose = pytest.importorskip("nose")
67

78

8-
def test_nose_setup(testdir):
9-
p = testdir.makepyfile(
9+
def test_nose_setup(pytester: Pytester) -> None:
10+
p = pytester.makepyfile(
1011
"""
1112
values = []
1213
from nose.tools import with_setup
@@ -22,11 +23,11 @@ def test_world():
2223
test_hello.teardown = lambda: values.append(2)
2324
"""
2425
)
25-
result = testdir.runpytest(p, "-p", "nose")
26+
result = pytester.runpytest(p, "-p", "nose")
2627
result.assert_outcomes(passed=2)
2728

2829

29-
def test_setup_func_with_setup_decorator():
30+
def test_setup_func_with_setup_decorator() -> None:
3031
from _pytest.nose import call_optional
3132

3233
values = []
@@ -40,7 +41,7 @@ def f(self):
4041
assert not values
4142

4243

43-
def test_setup_func_not_callable():
44+
def test_setup_func_not_callable() -> None:
4445
from _pytest.nose import call_optional
4546

4647
class A:
@@ -49,8 +50,8 @@ class A:
4950
call_optional(A(), "f")
5051

5152

52-
def test_nose_setup_func(testdir):
53-
p = testdir.makepyfile(
53+
def test_nose_setup_func(pytester: Pytester) -> None:
54+
p = pytester.makepyfile(
5455
"""
5556
from nose.tools import with_setup
5657
@@ -75,12 +76,12 @@ def test_world():
7576
7677
"""
7778
)
78-
result = testdir.runpytest(p, "-p", "nose")
79+
result = pytester.runpytest(p, "-p", "nose")
7980
result.assert_outcomes(passed=2)
8081

8182

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(
8485
"""
8586
from nose.tools import with_setup
8687
@@ -99,12 +100,12 @@ def test_world():
99100
100101
"""
101102
)
102-
result = testdir.runpytest(p, "-p", "nose")
103+
result = pytester.runpytest(p, "-p", "nose")
103104
result.stdout.fnmatch_lines(["*TypeError: <lambda>()*"])
104105

105106

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(
108109
"""
109110
values = []
110111
@@ -118,13 +119,13 @@ def test_hello():
118119
test_hello.teardown = my_teardown
119120
"""
120121
)
121-
reprec = testdir.inline_run()
122+
reprec = pytester.inline_run()
122123
reprec.assertoutcome(passed=1)
123124

124125

125-
def test_nose_setup_partial(testdir):
126+
def test_nose_setup_partial(pytester: Pytester) -> None:
126127
pytest.importorskip("functools")
127-
p = testdir.makepyfile(
128+
p = pytester.makepyfile(
128129
"""
129130
from functools import partial
130131
@@ -153,12 +154,12 @@ def test_world():
153154
test_hello.teardown = my_teardown_partial
154155
"""
155156
)
156-
result = testdir.runpytest(p, "-p", "nose")
157+
result = pytester.runpytest(p, "-p", "nose")
157158
result.stdout.fnmatch_lines(["*2 passed*"])
158159

159160

160-
def test_module_level_setup(testdir):
161-
testdir.makepyfile(
161+
def test_module_level_setup(pytester: Pytester) -> None:
162+
pytester.makepyfile(
162163
"""
163164
from nose.tools import with_setup
164165
items = {}
@@ -184,12 +185,12 @@ def test_local_setup():
184185
assert 1 not in items
185186
"""
186187
)
187-
result = testdir.runpytest("-p", "nose")
188+
result = pytester.runpytest("-p", "nose")
188189
result.stdout.fnmatch_lines(["*2 passed*"])
189190

190191

191-
def test_nose_style_setup_teardown(testdir):
192-
testdir.makepyfile(
192+
def test_nose_style_setup_teardown(pytester: Pytester) -> None:
193+
pytester.makepyfile(
193194
"""
194195
values = []
195196
@@ -206,12 +207,12 @@ def test_world():
206207
assert values == [1]
207208
"""
208209
)
209-
result = testdir.runpytest("-p", "nose")
210+
result = pytester.runpytest("-p", "nose")
210211
result.stdout.fnmatch_lines(["*2 passed*"])
211212

212213

213-
def test_nose_setup_ordering(testdir):
214-
testdir.makepyfile(
214+
def test_nose_setup_ordering(pytester: Pytester) -> None:
215+
pytester.makepyfile(
215216
"""
216217
def setup_module(mod):
217218
mod.visited = True
@@ -223,14 +224,14 @@ def test_first(self):
223224
pass
224225
"""
225226
)
226-
result = testdir.runpytest()
227+
result = pytester.runpytest()
227228
result.stdout.fnmatch_lines(["*1 passed*"])
228229

229230

230-
def test_apiwrapper_problem_issue260(testdir):
231+
def test_apiwrapper_problem_issue260(pytester: Pytester) -> None:
231232
# this would end up trying a call an optional teardown on the class
232233
# for plain unittests we don't want nose behaviour
233-
testdir.makepyfile(
234+
pytester.makepyfile(
234235
"""
235236
import unittest
236237
class TestCase(unittest.TestCase):
@@ -248,14 +249,14 @@ def test_fun(self):
248249
pass
249250
"""
250251
)
251-
result = testdir.runpytest()
252+
result = pytester.runpytest()
252253
result.assert_outcomes(passed=1)
253254

254255

255-
def test_setup_teardown_linking_issue265(testdir):
256+
def test_setup_teardown_linking_issue265(pytester: Pytester) -> None:
256257
# we accidentally didn't integrate nose setupstate with normal setupstate
257258
# this test ensures that won't happen again
258-
testdir.makepyfile(
259+
pytester.makepyfile(
259260
'''
260261
import pytest
261262
@@ -276,66 +277,66 @@ def teardown(self):
276277
raise Exception("should not call teardown for skipped tests")
277278
'''
278279
)
279-
reprec = testdir.runpytest()
280+
reprec = pytester.runpytest()
280281
reprec.assert_outcomes(passed=1, skipped=1)
281282

282283

283-
def test_SkipTest_during_collection(testdir):
284-
p = testdir.makepyfile(
284+
def test_SkipTest_during_collection(pytester: Pytester) -> None:
285+
p = pytester.makepyfile(
285286
"""
286287
import nose
287288
raise nose.SkipTest("during collection")
288289
def test_failing():
289290
assert False
290291
"""
291292
)
292-
result = testdir.runpytest(p)
293+
result = pytester.runpytest(p)
293294
result.assert_outcomes(skipped=1)
294295

295296

296-
def test_SkipTest_in_test(testdir):
297-
testdir.makepyfile(
297+
def test_SkipTest_in_test(pytester: Pytester) -> None:
298+
pytester.makepyfile(
298299
"""
299300
import nose
300301
301302
def test_skipping():
302303
raise nose.SkipTest("in test")
303304
"""
304305
)
305-
reprec = testdir.inline_run()
306+
reprec = pytester.inline_run()
306307
reprec.assertoutcome(skipped=1)
307308

308309

309-
def test_istest_function_decorator(testdir):
310-
p = testdir.makepyfile(
310+
def test_istest_function_decorator(pytester: Pytester) -> None:
311+
p = pytester.makepyfile(
311312
"""
312313
import nose.tools
313314
@nose.tools.istest
314315
def not_test_prefix():
315316
pass
316317
"""
317318
)
318-
result = testdir.runpytest(p)
319+
result = pytester.runpytest(p)
319320
result.assert_outcomes(passed=1)
320321

321322

322-
def test_nottest_function_decorator(testdir):
323-
testdir.makepyfile(
323+
def test_nottest_function_decorator(pytester: Pytester) -> None:
324+
pytester.makepyfile(
324325
"""
325326
import nose.tools
326327
@nose.tools.nottest
327328
def test_prefix():
328329
pass
329330
"""
330331
)
331-
reprec = testdir.inline_run()
332+
reprec = pytester.inline_run()
332333
assert not reprec.getfailedcollections()
333334
calls = reprec.getreports("pytest_runtest_logreport")
334335
assert not calls
335336

336337

337-
def test_istest_class_decorator(testdir):
338-
p = testdir.makepyfile(
338+
def test_istest_class_decorator(pytester: Pytester) -> None:
339+
p = pytester.makepyfile(
339340
"""
340341
import nose.tools
341342
@nose.tools.istest
@@ -344,12 +345,12 @@ def test_method(self):
344345
pass
345346
"""
346347
)
347-
result = testdir.runpytest(p)
348+
result = pytester.runpytest(p)
348349
result.assert_outcomes(passed=1)
349350

350351

351-
def test_nottest_class_decorator(testdir):
352-
testdir.makepyfile(
352+
def test_nottest_class_decorator(pytester: Pytester) -> None:
353+
pytester.makepyfile(
353354
"""
354355
import nose.tools
355356
@nose.tools.nottest
@@ -358,27 +359,27 @@ def test_method(self):
358359
pass
359360
"""
360361
)
361-
reprec = testdir.inline_run()
362+
reprec = pytester.inline_run()
362363
assert not reprec.getfailedcollections()
363364
calls = reprec.getreports("pytest_runtest_logreport")
364365
assert not calls
365366

366367

367-
def test_skip_test_with_unicode(testdir):
368-
testdir.makepyfile(
368+
def test_skip_test_with_unicode(pytester: Pytester) -> None:
369+
pytester.makepyfile(
369370
"""\
370371
import unittest
371372
class TestClass():
372373
def test_io(self):
373374
raise unittest.SkipTest('😊')
374375
"""
375376
)
376-
result = testdir.runpytest()
377+
result = pytester.runpytest()
377378
result.stdout.fnmatch_lines(["* 1 skipped *"])
378379

379380

380-
def test_raises(testdir):
381-
testdir.makepyfile(
381+
def test_raises(pytester: Pytester) -> None:
382+
pytester.makepyfile(
382383
"""
383384
from nose.tools import raises
384385
@@ -395,7 +396,7 @@ def test_raises_baseexception_caught():
395396
raise BaseException
396397
"""
397398
)
398-
result = testdir.runpytest("-vv")
399+
result = pytester.runpytest("-vv")
399400
result.stdout.fnmatch_lines(
400401
[
401402
"test_raises.py::test_raises_runtimeerror PASSED*",

0 commit comments

Comments
 (0)