Migrate test_nose.py from testdir to pytester
This commit is contained in:
parent
d1cb9de211
commit
d4c81ffab4
|
@ -1,12 +1,13 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
from _pytest.pytester import Pytester
|
||||||
|
|
||||||
|
|
||||||
def setup_module(mod):
|
def setup_module(mod):
|
||||||
mod.nose = pytest.importorskip("nose")
|
mod.nose = pytest.importorskip("nose")
|
||||||
|
|
||||||
|
|
||||||
def test_nose_setup(testdir):
|
def test_nose_setup(pytester: Pytester) -> None:
|
||||||
p = testdir.makepyfile(
|
p = pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
values = []
|
values = []
|
||||||
from nose.tools import with_setup
|
from nose.tools import with_setup
|
||||||
|
@ -22,11 +23,11 @@ def test_nose_setup(testdir):
|
||||||
test_hello.teardown = lambda: values.append(2)
|
test_hello.teardown = lambda: values.append(2)
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest(p, "-p", "nose")
|
result = pytester.runpytest(p, "-p", "nose")
|
||||||
result.assert_outcomes(passed=2)
|
result.assert_outcomes(passed=2)
|
||||||
|
|
||||||
|
|
||||||
def test_setup_func_with_setup_decorator():
|
def test_setup_func_with_setup_decorator() -> None:
|
||||||
from _pytest.nose import call_optional
|
from _pytest.nose import call_optional
|
||||||
|
|
||||||
values = []
|
values = []
|
||||||
|
@ -40,7 +41,7 @@ def test_setup_func_with_setup_decorator():
|
||||||
assert not values
|
assert not values
|
||||||
|
|
||||||
|
|
||||||
def test_setup_func_not_callable():
|
def test_setup_func_not_callable() -> None:
|
||||||
from _pytest.nose import call_optional
|
from _pytest.nose import call_optional
|
||||||
|
|
||||||
class A:
|
class A:
|
||||||
|
@ -49,8 +50,8 @@ def test_setup_func_not_callable():
|
||||||
call_optional(A(), "f")
|
call_optional(A(), "f")
|
||||||
|
|
||||||
|
|
||||||
def test_nose_setup_func(testdir):
|
def test_nose_setup_func(pytester: Pytester) -> None:
|
||||||
p = testdir.makepyfile(
|
p = pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
from nose.tools import with_setup
|
from nose.tools import with_setup
|
||||||
|
|
||||||
|
@ -75,12 +76,12 @@ def test_nose_setup_func(testdir):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest(p, "-p", "nose")
|
result = pytester.runpytest(p, "-p", "nose")
|
||||||
result.assert_outcomes(passed=2)
|
result.assert_outcomes(passed=2)
|
||||||
|
|
||||||
|
|
||||||
def test_nose_setup_func_failure(testdir):
|
def test_nose_setup_func_failure(pytester: Pytester) -> None:
|
||||||
p = testdir.makepyfile(
|
p = pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
from nose.tools import with_setup
|
from nose.tools import with_setup
|
||||||
|
|
||||||
|
@ -99,12 +100,12 @@ def test_nose_setup_func_failure(testdir):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest(p, "-p", "nose")
|
result = pytester.runpytest(p, "-p", "nose")
|
||||||
result.stdout.fnmatch_lines(["*TypeError: <lambda>()*"])
|
result.stdout.fnmatch_lines(["*TypeError: <lambda>()*"])
|
||||||
|
|
||||||
|
|
||||||
def test_nose_setup_func_failure_2(testdir):
|
def test_nose_setup_func_failure_2(pytester: Pytester) -> None:
|
||||||
testdir.makepyfile(
|
pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
values = []
|
values = []
|
||||||
|
|
||||||
|
@ -118,13 +119,13 @@ def test_nose_setup_func_failure_2(testdir):
|
||||||
test_hello.teardown = my_teardown
|
test_hello.teardown = my_teardown
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
reprec = testdir.inline_run()
|
reprec = pytester.inline_run()
|
||||||
reprec.assertoutcome(passed=1)
|
reprec.assertoutcome(passed=1)
|
||||||
|
|
||||||
|
|
||||||
def test_nose_setup_partial(testdir):
|
def test_nose_setup_partial(pytester: Pytester) -> None:
|
||||||
pytest.importorskip("functools")
|
pytest.importorskip("functools")
|
||||||
p = testdir.makepyfile(
|
p = pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
@ -153,12 +154,12 @@ def test_nose_setup_partial(testdir):
|
||||||
test_hello.teardown = my_teardown_partial
|
test_hello.teardown = my_teardown_partial
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest(p, "-p", "nose")
|
result = pytester.runpytest(p, "-p", "nose")
|
||||||
result.stdout.fnmatch_lines(["*2 passed*"])
|
result.stdout.fnmatch_lines(["*2 passed*"])
|
||||||
|
|
||||||
|
|
||||||
def test_module_level_setup(testdir):
|
def test_module_level_setup(pytester: Pytester) -> None:
|
||||||
testdir.makepyfile(
|
pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
from nose.tools import with_setup
|
from nose.tools import with_setup
|
||||||
items = {}
|
items = {}
|
||||||
|
@ -184,12 +185,12 @@ def test_module_level_setup(testdir):
|
||||||
assert 1 not in items
|
assert 1 not in items
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest("-p", "nose")
|
result = pytester.runpytest("-p", "nose")
|
||||||
result.stdout.fnmatch_lines(["*2 passed*"])
|
result.stdout.fnmatch_lines(["*2 passed*"])
|
||||||
|
|
||||||
|
|
||||||
def test_nose_style_setup_teardown(testdir):
|
def test_nose_style_setup_teardown(pytester: Pytester) -> None:
|
||||||
testdir.makepyfile(
|
pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
values = []
|
values = []
|
||||||
|
|
||||||
|
@ -206,12 +207,12 @@ def test_nose_style_setup_teardown(testdir):
|
||||||
assert values == [1]
|
assert values == [1]
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest("-p", "nose")
|
result = pytester.runpytest("-p", "nose")
|
||||||
result.stdout.fnmatch_lines(["*2 passed*"])
|
result.stdout.fnmatch_lines(["*2 passed*"])
|
||||||
|
|
||||||
|
|
||||||
def test_nose_setup_ordering(testdir):
|
def test_nose_setup_ordering(pytester: Pytester) -> None:
|
||||||
testdir.makepyfile(
|
pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
def setup_module(mod):
|
def setup_module(mod):
|
||||||
mod.visited = True
|
mod.visited = True
|
||||||
|
@ -223,14 +224,14 @@ def test_nose_setup_ordering(testdir):
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest()
|
result = pytester.runpytest()
|
||||||
result.stdout.fnmatch_lines(["*1 passed*"])
|
result.stdout.fnmatch_lines(["*1 passed*"])
|
||||||
|
|
||||||
|
|
||||||
def test_apiwrapper_problem_issue260(testdir):
|
def test_apiwrapper_problem_issue260(pytester: Pytester) -> None:
|
||||||
# this would end up trying a call an optional teardown on the class
|
# this would end up trying a call an optional teardown on the class
|
||||||
# for plain unittests we don't want nose behaviour
|
# for plain unittests we don't want nose behaviour
|
||||||
testdir.makepyfile(
|
pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
import unittest
|
import unittest
|
||||||
class TestCase(unittest.TestCase):
|
class TestCase(unittest.TestCase):
|
||||||
|
@ -248,14 +249,14 @@ def test_apiwrapper_problem_issue260(testdir):
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest()
|
result = pytester.runpytest()
|
||||||
result.assert_outcomes(passed=1)
|
result.assert_outcomes(passed=1)
|
||||||
|
|
||||||
|
|
||||||
def test_setup_teardown_linking_issue265(testdir):
|
def test_setup_teardown_linking_issue265(pytester: Pytester) -> None:
|
||||||
# we accidentally didn't integrate nose setupstate with normal setupstate
|
# we accidentally didn't integrate nose setupstate with normal setupstate
|
||||||
# this test ensures that won't happen again
|
# this test ensures that won't happen again
|
||||||
testdir.makepyfile(
|
pytester.makepyfile(
|
||||||
'''
|
'''
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -276,12 +277,12 @@ def test_setup_teardown_linking_issue265(testdir):
|
||||||
raise Exception("should not call teardown for skipped tests")
|
raise Exception("should not call teardown for skipped tests")
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
reprec = testdir.runpytest()
|
reprec = pytester.runpytest()
|
||||||
reprec.assert_outcomes(passed=1, skipped=1)
|
reprec.assert_outcomes(passed=1, skipped=1)
|
||||||
|
|
||||||
|
|
||||||
def test_SkipTest_during_collection(testdir):
|
def test_SkipTest_during_collection(pytester: Pytester) -> None:
|
||||||
p = testdir.makepyfile(
|
p = pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
import nose
|
import nose
|
||||||
raise nose.SkipTest("during collection")
|
raise nose.SkipTest("during collection")
|
||||||
|
@ -289,12 +290,12 @@ def test_SkipTest_during_collection(testdir):
|
||||||
assert False
|
assert False
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest(p)
|
result = pytester.runpytest(p)
|
||||||
result.assert_outcomes(skipped=1)
|
result.assert_outcomes(skipped=1)
|
||||||
|
|
||||||
|
|
||||||
def test_SkipTest_in_test(testdir):
|
def test_SkipTest_in_test(pytester: Pytester) -> None:
|
||||||
testdir.makepyfile(
|
pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
import nose
|
import nose
|
||||||
|
|
||||||
|
@ -302,12 +303,12 @@ def test_SkipTest_in_test(testdir):
|
||||||
raise nose.SkipTest("in test")
|
raise nose.SkipTest("in test")
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
reprec = testdir.inline_run()
|
reprec = pytester.inline_run()
|
||||||
reprec.assertoutcome(skipped=1)
|
reprec.assertoutcome(skipped=1)
|
||||||
|
|
||||||
|
|
||||||
def test_istest_function_decorator(testdir):
|
def test_istest_function_decorator(pytester: Pytester) -> None:
|
||||||
p = testdir.makepyfile(
|
p = pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
import nose.tools
|
import nose.tools
|
||||||
@nose.tools.istest
|
@nose.tools.istest
|
||||||
|
@ -315,12 +316,12 @@ def test_istest_function_decorator(testdir):
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest(p)
|
result = pytester.runpytest(p)
|
||||||
result.assert_outcomes(passed=1)
|
result.assert_outcomes(passed=1)
|
||||||
|
|
||||||
|
|
||||||
def test_nottest_function_decorator(testdir):
|
def test_nottest_function_decorator(pytester: Pytester) -> None:
|
||||||
testdir.makepyfile(
|
pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
import nose.tools
|
import nose.tools
|
||||||
@nose.tools.nottest
|
@nose.tools.nottest
|
||||||
|
@ -328,14 +329,14 @@ def test_nottest_function_decorator(testdir):
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
reprec = testdir.inline_run()
|
reprec = pytester.inline_run()
|
||||||
assert not reprec.getfailedcollections()
|
assert not reprec.getfailedcollections()
|
||||||
calls = reprec.getreports("pytest_runtest_logreport")
|
calls = reprec.getreports("pytest_runtest_logreport")
|
||||||
assert not calls
|
assert not calls
|
||||||
|
|
||||||
|
|
||||||
def test_istest_class_decorator(testdir):
|
def test_istest_class_decorator(pytester: Pytester) -> None:
|
||||||
p = testdir.makepyfile(
|
p = pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
import nose.tools
|
import nose.tools
|
||||||
@nose.tools.istest
|
@nose.tools.istest
|
||||||
|
@ -344,12 +345,12 @@ def test_istest_class_decorator(testdir):
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest(p)
|
result = pytester.runpytest(p)
|
||||||
result.assert_outcomes(passed=1)
|
result.assert_outcomes(passed=1)
|
||||||
|
|
||||||
|
|
||||||
def test_nottest_class_decorator(testdir):
|
def test_nottest_class_decorator(pytester: Pytester) -> None:
|
||||||
testdir.makepyfile(
|
pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
import nose.tools
|
import nose.tools
|
||||||
@nose.tools.nottest
|
@nose.tools.nottest
|
||||||
|
@ -358,14 +359,14 @@ def test_nottest_class_decorator(testdir):
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
reprec = testdir.inline_run()
|
reprec = pytester.inline_run()
|
||||||
assert not reprec.getfailedcollections()
|
assert not reprec.getfailedcollections()
|
||||||
calls = reprec.getreports("pytest_runtest_logreport")
|
calls = reprec.getreports("pytest_runtest_logreport")
|
||||||
assert not calls
|
assert not calls
|
||||||
|
|
||||||
|
|
||||||
def test_skip_test_with_unicode(testdir):
|
def test_skip_test_with_unicode(pytester: Pytester) -> None:
|
||||||
testdir.makepyfile(
|
pytester.makepyfile(
|
||||||
"""\
|
"""\
|
||||||
import unittest
|
import unittest
|
||||||
class TestClass():
|
class TestClass():
|
||||||
|
@ -373,12 +374,12 @@ def test_skip_test_with_unicode(testdir):
|
||||||
raise unittest.SkipTest('😊')
|
raise unittest.SkipTest('😊')
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest()
|
result = pytester.runpytest()
|
||||||
result.stdout.fnmatch_lines(["* 1 skipped *"])
|
result.stdout.fnmatch_lines(["* 1 skipped *"])
|
||||||
|
|
||||||
|
|
||||||
def test_raises(testdir):
|
def test_raises(pytester: Pytester) -> None:
|
||||||
testdir.makepyfile(
|
pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
from nose.tools import raises
|
from nose.tools import raises
|
||||||
|
|
||||||
|
@ -395,7 +396,7 @@ def test_raises(testdir):
|
||||||
raise BaseException
|
raise BaseException
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest("-vv")
|
result = pytester.runpytest("-vv")
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
[
|
[
|
||||||
"test_raises.py::test_raises_runtimeerror PASSED*",
|
"test_raises.py::test_raises_runtimeerror PASSED*",
|
||||||
|
|
Loading…
Reference in New Issue