2017-03-17 09:21:30 +08:00
|
|
|
from __future__ import absolute_import, division, print_function
|
2016-07-23 22:56:04 +08:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
def test_yield_tests_deprecation(testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2016-07-23 22:56:04 +08:00
|
|
|
def func1(arg, arg2):
|
|
|
|
assert arg == arg2
|
|
|
|
def test_gen():
|
|
|
|
yield "m1", func1, 15, 3*5
|
|
|
|
yield "m2", func1, 42, 6*7
|
2017-07-11 03:07:55 +08:00
|
|
|
def test_gen2():
|
|
|
|
for k in range(10):
|
|
|
|
yield func1, 1, 1
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
result = testdir.runpytest("-ra")
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"*yield tests are deprecated, and scheduled to be removed in pytest 4.0*",
|
|
|
|
"*2 passed*",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
assert result.stdout.str().count("yield tests are deprecated") == 2
|
2016-07-23 22:56:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_funcarg_prefix_deprecation(testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2016-07-23 22:56:04 +08:00
|
|
|
def pytest_funcarg__value():
|
|
|
|
return 10
|
|
|
|
|
|
|
|
def test_funcarg_prefix(value):
|
|
|
|
assert value == 10
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
result = testdir.runpytest("-ra")
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
(
|
|
|
|
"*pytest_funcarg__value: "
|
|
|
|
'declaring fixtures using "pytest_funcarg__" prefix is deprecated '
|
|
|
|
"and scheduled to be removed in pytest 4.0. "
|
|
|
|
"Please remove the prefix and use the @pytest.fixture decorator instead."
|
|
|
|
),
|
|
|
|
"*1 passed*",
|
|
|
|
]
|
|
|
|
)
|
2016-07-23 22:56:04 +08:00
|
|
|
|
|
|
|
|
2016-08-17 08:30:07 +08:00
|
|
|
def test_pytest_setup_cfg_deprecated(testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makefile(
|
|
|
|
".cfg",
|
|
|
|
setup="""
|
2016-08-17 08:30:07 +08:00
|
|
|
[pytest]
|
|
|
|
addopts = --verbose
|
2018-05-23 22:48:46 +08:00
|
|
|
""",
|
|
|
|
)
|
2016-08-17 08:30:07 +08:00
|
|
|
result = testdir.runpytest()
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
["*pytest*section in setup.cfg files is deprecated*use*tool:pytest*instead*"]
|
|
|
|
)
|
2016-08-17 08:30:07 +08:00
|
|
|
|
|
|
|
|
2018-03-02 15:52:38 +08:00
|
|
|
def test_pytest_custom_cfg_deprecated(testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makefile(
|
|
|
|
".cfg",
|
|
|
|
custom="""
|
2018-03-02 15:52:38 +08:00
|
|
|
[pytest]
|
|
|
|
addopts = --verbose
|
2018-05-23 22:48:46 +08:00
|
|
|
""",
|
|
|
|
)
|
2018-03-02 15:52:38 +08:00
|
|
|
result = testdir.runpytest("-c", "custom.cfg")
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
["*pytest*section in custom.cfg files is deprecated*use*tool:pytest*instead*"]
|
|
|
|
)
|
2018-03-02 15:52:38 +08:00
|
|
|
|
|
|
|
|
2016-07-23 22:56:04 +08:00
|
|
|
def test_str_args_deprecated(tmpdir, testdir):
|
|
|
|
"""Deprecate passing strings to pytest.main(). Scheduled for removal in pytest-4.0."""
|
|
|
|
from _pytest.main import EXIT_NOTESTSCOLLECTED
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2016-07-23 22:56:04 +08:00
|
|
|
warnings = []
|
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class Collect(object):
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2016-07-23 22:56:04 +08:00
|
|
|
def pytest_logwarning(self, message):
|
|
|
|
warnings.append(message)
|
|
|
|
|
|
|
|
ret = pytest.main("%s -x" % tmpdir, plugins=[Collect()])
|
2018-05-23 22:48:46 +08:00
|
|
|
msg = (
|
|
|
|
"passing a string to pytest.main() is deprecated, "
|
|
|
|
"pass a list of arguments instead."
|
|
|
|
)
|
2016-07-23 22:56:04 +08:00
|
|
|
assert msg in warnings
|
|
|
|
assert ret == EXIT_NOTESTSCOLLECTED
|
|
|
|
|
|
|
|
|
|
|
|
def test_getfuncargvalue_is_deprecated(request):
|
2018-05-23 22:48:46 +08:00
|
|
|
pytest.deprecated_call(request.getfuncargvalue, "tmpdir")
|
2016-08-17 07:22:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_resultlog_is_deprecated(testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
result = testdir.runpytest("--help")
|
|
|
|
result.stdout.fnmatch_lines(["*DEPRECATED path for machine-readable result log*"])
|
2016-08-17 07:22:15 +08:00
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2016-08-17 07:22:15 +08:00
|
|
|
def test():
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
result = testdir.runpytest("--result-log=%s" % testdir.tmpdir.join("result.log"))
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"*--result-log is deprecated and scheduled for removal in pytest 4.0*",
|
|
|
|
"*See https://docs.pytest.org/*/usage.html#creating-resultlog-format-files for more information*",
|
|
|
|
]
|
|
|
|
)
|
2017-11-15 23:48:08 +08:00
|
|
|
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
@pytest.mark.filterwarnings("always:Metafunc.addcall is deprecated")
|
2017-11-15 23:48:08 +08:00
|
|
|
def test_metafunc_addcall_deprecated(testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2017-11-15 23:48:08 +08:00
|
|
|
def pytest_generate_tests(metafunc):
|
|
|
|
metafunc.addcall({'i': 1})
|
|
|
|
metafunc.addcall({'i': 2})
|
|
|
|
def test_func(i):
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
res = testdir.runpytest("-s")
|
2017-11-15 23:48:08 +08:00
|
|
|
assert res.ret == 0
|
2018-05-23 22:48:46 +08:00
|
|
|
res.stdout.fnmatch_lines(
|
|
|
|
["*Metafunc.addcall is deprecated*", "*2 passed, 2 warnings*"]
|
|
|
|
)
|
2017-11-24 05:34:52 +08:00
|
|
|
|
|
|
|
|
2017-12-01 04:34:53 +08:00
|
|
|
def test_terminal_reporter_writer_attr(pytestconfig):
|
|
|
|
"""Check that TerminalReporter._tw is also available as 'writer' (#2984)
|
|
|
|
This attribute is planned to be deprecated in 3.4.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
import xdist # noqa
|
2018-05-23 22:48:46 +08:00
|
|
|
|
|
|
|
pytest.skip("xdist workers disable the terminal reporter plugin")
|
2017-12-01 04:34:53 +08:00
|
|
|
except ImportError:
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
terminal_reporter = pytestconfig.pluginmanager.get_plugin("terminalreporter")
|
2017-12-01 04:34:53 +08:00
|
|
|
assert terminal_reporter.writer is terminal_reporter._tw
|
|
|
|
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
@pytest.mark.parametrize("plugin", ["catchlog", "capturelog"])
|
2017-12-06 03:02:56 +08:00
|
|
|
def test_pytest_catchlog_deprecated(testdir, plugin):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2017-11-24 05:34:52 +08:00
|
|
|
def test_func(pytestconfig):
|
2018-05-18 05:31:16 +08:00
|
|
|
pytestconfig.pluginmanager.register(None, 'pytest_{}')
|
2018-05-23 22:48:46 +08:00
|
|
|
""".format(
|
|
|
|
plugin
|
|
|
|
)
|
|
|
|
)
|
2017-11-24 05:34:52 +08:00
|
|
|
res = testdir.runpytest()
|
|
|
|
assert res.ret == 0
|
2018-05-23 22:48:46 +08:00
|
|
|
res.stdout.fnmatch_lines(
|
|
|
|
["*pytest-*log plugin has been merged into the core*", "*1 passed, 1 warnings*"]
|
|
|
|
)
|
2018-02-21 07:27:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_pytest_plugins_in_non_top_level_conftest_deprecated(testdir):
|
|
|
|
from _pytest.deprecated import PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2018-02-21 07:27:24 +08:00
|
|
|
subdirectory = testdir.tmpdir.join("subdirectory")
|
|
|
|
subdirectory.mkdir()
|
|
|
|
# create the inner conftest with makeconftest and then move it to the subdirectory
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2018-02-21 07:27:24 +08:00
|
|
|
pytest_plugins=['capture']
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2018-02-21 07:27:24 +08:00
|
|
|
testdir.tmpdir.join("conftest.py").move(subdirectory.join("conftest.py"))
|
|
|
|
# make the top level conftest
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2018-02-21 07:27:24 +08:00
|
|
|
import warnings
|
|
|
|
warnings.filterwarnings('always', category=DeprecationWarning)
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2018-02-21 07:27:24 +08:00
|
|
|
def test_func():
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2018-02-21 07:27:24 +08:00
|
|
|
res = testdir.runpytest_subprocess()
|
|
|
|
assert res.ret == 0
|
2018-05-23 22:48:46 +08:00
|
|
|
res.stderr.fnmatch_lines(
|
|
|
|
"*" + str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
|
|
|
|
)
|
2018-02-21 07:27:24 +08:00
|
|
|
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
def test_pytest_plugins_in_non_top_level_conftest_deprecated_no_top_level_conftest(
|
|
|
|
testdir
|
|
|
|
):
|
2018-02-21 07:27:24 +08:00
|
|
|
from _pytest.deprecated import PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
|
2018-05-23 22:48:46 +08:00
|
|
|
|
|
|
|
subdirectory = testdir.tmpdir.join("subdirectory")
|
2018-02-21 07:27:24 +08:00
|
|
|
subdirectory.mkdir()
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2018-02-21 07:27:24 +08:00
|
|
|
import warnings
|
|
|
|
warnings.filterwarnings('always', category=DeprecationWarning)
|
|
|
|
pytest_plugins=['capture']
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2018-02-21 07:27:24 +08:00
|
|
|
testdir.tmpdir.join("conftest.py").move(subdirectory.join("conftest.py"))
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2018-02-21 07:27:24 +08:00
|
|
|
def test_func():
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2018-02-21 07:27:24 +08:00
|
|
|
|
|
|
|
res = testdir.runpytest_subprocess()
|
|
|
|
assert res.ret == 0
|
2018-05-23 22:48:46 +08:00
|
|
|
res.stderr.fnmatch_lines(
|
|
|
|
"*" + str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
|
|
|
|
)
|
2018-02-21 07:27:24 +08:00
|
|
|
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
def test_pytest_plugins_in_non_top_level_conftest_deprecated_no_false_positives(
|
|
|
|
testdir
|
|
|
|
):
|
2018-02-21 07:27:24 +08:00
|
|
|
from _pytest.deprecated import PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
|
2018-05-23 22:48:46 +08:00
|
|
|
|
|
|
|
subdirectory = testdir.tmpdir.join("subdirectory")
|
2018-02-21 07:27:24 +08:00
|
|
|
subdirectory.mkdir()
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2018-02-21 07:27:24 +08:00
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2018-02-21 07:27:24 +08:00
|
|
|
testdir.tmpdir.join("conftest.py").move(subdirectory.join("conftest.py"))
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2018-02-21 07:27:24 +08:00
|
|
|
import warnings
|
|
|
|
warnings.filterwarnings('always', category=DeprecationWarning)
|
|
|
|
pytest_plugins=['capture']
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2018-02-21 07:27:24 +08:00
|
|
|
def test_func():
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2018-02-21 07:27:24 +08:00
|
|
|
res = testdir.runpytest_subprocess()
|
|
|
|
assert res.ret == 0
|
2018-05-23 22:48:46 +08:00
|
|
|
assert str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[
|
|
|
|
0
|
|
|
|
] not in res.stderr.str()
|