Merge pull request #1758 from nicoddemus/deprecated-module
Add deprecation module to centralize deprecation messages and bits of…
This commit is contained in:
commit
510a6083ba
|
@ -115,10 +115,8 @@ def _prepareconfig(args=None, plugins=None):
|
||||||
if not isinstance(args, str):
|
if not isinstance(args, str):
|
||||||
raise ValueError("not a string or argument list: %r" % (args,))
|
raise ValueError("not a string or argument list: %r" % (args,))
|
||||||
args = shlex.split(args, posix=sys.platform != "win32")
|
args = shlex.split(args, posix=sys.platform != "win32")
|
||||||
# we want to remove this way of passing arguments to pytest.main()
|
from _pytest import deprecated
|
||||||
# in pytest-4.0
|
warning = deprecated.MAIN_STR_ARGS
|
||||||
warning = ('passing a string to pytest.main() is deprecated, '
|
|
||||||
'pass a list of arguments instead.')
|
|
||||||
config = get_config()
|
config = get_config()
|
||||||
pluginmanager = config.pluginmanager
|
pluginmanager = config.pluginmanager
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
"""
|
||||||
|
This module contains deprecation messages and bits of code used elsewhere in the codebase
|
||||||
|
that is planned to be removed in the next pytest release.
|
||||||
|
|
||||||
|
Keeping it in a central location makes it easy to track what is deprecated and should
|
||||||
|
be removed when the time comes.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
MAIN_STR_ARGS = 'passing a string to pytest.main() is deprecated, ' \
|
||||||
|
'pass a list of arguments instead.'
|
||||||
|
|
||||||
|
YIELD_TESTS = 'yield tests are deprecated, and scheduled to be removed in pytest 4.0'
|
||||||
|
|
||||||
|
FUNCARG_PREFIX = (
|
||||||
|
'{name}: 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.')
|
||||||
|
|
||||||
|
GETFUNCARGVALUE = "use of getfuncargvalue is deprecated, use getfixturevalue"
|
||||||
|
|
|
@ -450,8 +450,9 @@ class FixtureRequest(FuncargnamesCompatAttr):
|
||||||
|
|
||||||
def getfuncargvalue(self, argname):
|
def getfuncargvalue(self, argname):
|
||||||
""" Deprecated, use getfixturevalue. """
|
""" Deprecated, use getfixturevalue. """
|
||||||
|
from _pytest import deprecated
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"use of getfuncargvalue is deprecated, use getfixturevalue",
|
deprecated.GETFUNCARGVALUE,
|
||||||
DeprecationWarning)
|
DeprecationWarning)
|
||||||
return self.getfixturevalue(argname)
|
return self.getfixturevalue(argname)
|
||||||
|
|
||||||
|
@ -885,10 +886,6 @@ def yield_fixture(scope="function", params=None, autouse=False, ids=None, name=N
|
||||||
|
|
||||||
|
|
||||||
defaultfuncargprefixmarker = fixture()
|
defaultfuncargprefixmarker = fixture()
|
||||||
funcarg_prefix_warning = (
|
|
||||||
'{name}: 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.')
|
|
||||||
|
|
||||||
|
|
||||||
@fixture(scope="session")
|
@fixture(scope="session")
|
||||||
|
@ -1071,7 +1068,8 @@ class FixtureManager:
|
||||||
if not callable(obj):
|
if not callable(obj):
|
||||||
continue
|
continue
|
||||||
marker = defaultfuncargprefixmarker
|
marker = defaultfuncargprefixmarker
|
||||||
self.config.warn('C1', funcarg_prefix_warning.format(name=name))
|
from _pytest import deprecated
|
||||||
|
self.config.warn('C1', deprecated.FUNCARG_PREFIX.format(name=name))
|
||||||
name = name[len(self._argprefix):]
|
name = name[len(self._argprefix):]
|
||||||
elif not isinstance(marker, FixtureFunctionMarker):
|
elif not isinstance(marker, FixtureFunctionMarker):
|
||||||
# magic globals with __getattr__ might have got us a wrong
|
# magic globals with __getattr__ might have got us a wrong
|
||||||
|
|
|
@ -588,6 +588,7 @@ class Generator(FunctionMixin, PyCollector):
|
||||||
# test generators are seen as collectors but they also
|
# test generators are seen as collectors but they also
|
||||||
# invoke setup/teardown on popular request
|
# invoke setup/teardown on popular request
|
||||||
# (induced by the common "test_*" naming shared with normal tests)
|
# (induced by the common "test_*" naming shared with normal tests)
|
||||||
|
from _pytest import deprecated
|
||||||
self.session._setupstate.prepare(self)
|
self.session._setupstate.prepare(self)
|
||||||
# see FunctionMixin.setup and test_setupstate_is_preserved_134
|
# see FunctionMixin.setup and test_setupstate_is_preserved_134
|
||||||
self._preservedparent = self.parent.obj
|
self._preservedparent = self.parent.obj
|
||||||
|
@ -605,8 +606,7 @@ class Generator(FunctionMixin, PyCollector):
|
||||||
raise ValueError("%r generated tests with non-unique name %r" %(self, name))
|
raise ValueError("%r generated tests with non-unique name %r" %(self, name))
|
||||||
seen[name] = True
|
seen[name] = True
|
||||||
l.append(self.Function(name, self, args=args, callobj=call))
|
l.append(self.Function(name, self, args=args, callobj=call))
|
||||||
msg = 'yield tests are deprecated, and scheduled to be removed in pytest 4.0'
|
self.config.warn('C1', deprecated.YIELD_TESTS, fslocation=self.fspath)
|
||||||
self.config.warn('C1', msg, fslocation=self.fspath)
|
|
||||||
return l
|
return l
|
||||||
|
|
||||||
def getcallargs(self, obj):
|
def getcallargs(self, obj):
|
||||||
|
|
|
@ -763,51 +763,3 @@ class TestDurationWithFixture:
|
||||||
* call *test_1*
|
* call *test_1*
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
|
||||||
def test_yield_tests_deprecation(testdir):
|
|
||||||
testdir.makepyfile("""
|
|
||||||
def func1(arg, arg2):
|
|
||||||
assert arg == arg2
|
|
||||||
def test_gen():
|
|
||||||
yield "m1", func1, 15, 3*5
|
|
||||||
yield "m2", func1, 42, 6*7
|
|
||||||
""")
|
|
||||||
result = testdir.runpytest('-ra')
|
|
||||||
result.stdout.fnmatch_lines([
|
|
||||||
'*yield tests are deprecated, and scheduled to be removed in pytest 4.0*',
|
|
||||||
'*2 passed*',
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
def test_funcarg_prefix_deprecation(testdir):
|
|
||||||
testdir.makepyfile("""
|
|
||||||
def pytest_funcarg__value():
|
|
||||||
return 10
|
|
||||||
|
|
||||||
def test_funcarg_prefix(value):
|
|
||||||
assert value == 10
|
|
||||||
""")
|
|
||||||
result = testdir.runpytest('-ra')
|
|
||||||
result.stdout.fnmatch_lines([
|
|
||||||
('WC1 None 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*',
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
def test_str_args_deprecated(tmpdir, testdir):
|
|
||||||
"""Deprecate passing strings to pytest.main(). Scheduled for removal in pytest-4.0."""
|
|
||||||
warnings = []
|
|
||||||
|
|
||||||
class Collect:
|
|
||||||
def pytest_logwarning(self, message):
|
|
||||||
warnings.append(message)
|
|
||||||
|
|
||||||
ret = pytest.main("%s -x" % tmpdir, plugins=[Collect()])
|
|
||||||
testdir.delete_loaded_modules()
|
|
||||||
msg = ('passing a string to pytest.main() is deprecated, '
|
|
||||||
'pass a list of arguments instead.')
|
|
||||||
assert msg in warnings
|
|
||||||
assert ret == EXIT_NOTESTSCOLLECTED
|
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def test_yield_tests_deprecation(testdir):
|
||||||
|
testdir.makepyfile("""
|
||||||
|
def func1(arg, arg2):
|
||||||
|
assert arg == arg2
|
||||||
|
def test_gen():
|
||||||
|
yield "m1", func1, 15, 3*5
|
||||||
|
yield "m2", func1, 42, 6*7
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest('-ra')
|
||||||
|
result.stdout.fnmatch_lines([
|
||||||
|
'*yield tests are deprecated, and scheduled to be removed in pytest 4.0*',
|
||||||
|
'*2 passed*',
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def test_funcarg_prefix_deprecation(testdir):
|
||||||
|
testdir.makepyfile("""
|
||||||
|
def pytest_funcarg__value():
|
||||||
|
return 10
|
||||||
|
|
||||||
|
def test_funcarg_prefix(value):
|
||||||
|
assert value == 10
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest('-ra')
|
||||||
|
result.stdout.fnmatch_lines([
|
||||||
|
('WC1 None 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*',
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
warnings = []
|
||||||
|
|
||||||
|
class Collect:
|
||||||
|
def pytest_logwarning(self, message):
|
||||||
|
warnings.append(message)
|
||||||
|
|
||||||
|
ret = pytest.main("%s -x" % tmpdir, plugins=[Collect()])
|
||||||
|
testdir.delete_loaded_modules()
|
||||||
|
msg = ('passing a string to pytest.main() is deprecated, '
|
||||||
|
'pass a list of arguments instead.')
|
||||||
|
assert msg in warnings
|
||||||
|
assert ret == EXIT_NOTESTSCOLLECTED
|
||||||
|
|
||||||
|
|
||||||
|
def test_getfuncargvalue_is_deprecated(request):
|
||||||
|
pytest.deprecated_call(request.getfuncargvalue, 'tmpdir')
|
|
@ -2941,5 +2941,4 @@ class TestParameterizedSubRequest:
|
||||||
""".format(fixfile.strpath, testfile.basename))
|
""".format(fixfile.strpath, testfile.basename))
|
||||||
|
|
||||||
|
|
||||||
def test_getfuncargvalue_is_deprecated(request):
|
|
||||||
pytest.deprecated_call(request.getfuncargvalue, 'tmpdir')
|
|
||||||
|
|
|
@ -29,7 +29,6 @@ def test_funcarg(testdir):
|
||||||
assert bn == "qwe__abc"
|
assert bn == "qwe__abc"
|
||||||
|
|
||||||
def test_ensuretemp(recwarn):
|
def test_ensuretemp(recwarn):
|
||||||
#pytest.deprecated_call(pytest.ensuretemp, 'hello')
|
|
||||||
d1 = pytest.ensuretemp('hello')
|
d1 = pytest.ensuretemp('hello')
|
||||||
d2 = pytest.ensuretemp('hello')
|
d2 = pytest.ensuretemp('hello')
|
||||||
assert d1 == d2
|
assert d1 == d2
|
||||||
|
|
Loading…
Reference in New Issue