Move warning messages to _pytest.deprecated

This commit is contained in:
Bruno Oliveira 2018-09-13 15:56:50 -03:00
parent feb8240410
commit 32ee0b9c88
3 changed files with 29 additions and 14 deletions

View File

@ -18,6 +18,22 @@ YIELD_TESTS = RemovedInPytest4Warning(
"yield tests are deprecated, and scheduled to be removed in pytest 4.0"
)
CACHED_SETUP = RemovedInPytest4Warning(
"cached_setup is deprecated and will be removed in a future release. "
"Use standard fixture functions instead."
)
COMPAT_PROPERTY = (
"usage of {owner}.{name} is deprecated, please use pytest.{name} instead"
)
CUSTOM_CLASS = (
'use of special named "{name}" objects in collectors of type "{type_name}" to '
"customize the created nodes is deprecated. "
"Use pytest_pycollect_makeitem(...) to create custom "
"collection nodes instead."
)
FUNCARG_PREFIX = (
'{name}: declaring fixtures using "pytest_funcarg__" prefix is deprecated '
"and scheduled to be removed in pytest 4.0. "

View File

@ -479,11 +479,9 @@ class FixtureRequest(FuncargnamesCompatAttr):
or ``session`` indicating the caching lifecycle of the resource.
:arg extrakey: added to internal caching key of (funcargname, scope).
"""
msg = (
"cached_setup is deprecated and will be removed in a future release. "
"Use standard fixture functions instead."
)
warnings.warn(RemovedInPytest4Warning(msg), stacklevel=2)
from _pytest.deprecated import CACHED_SETUP
warnings.warn(CACHED_SETUP, stacklevel=2)
if not hasattr(self.config, "_setupcache"):
self.config._setupcache = {} # XXX weakref?
cachekey = (self.fixturename, self._getscopeitem(scope), extrakey)

View File

@ -62,11 +62,12 @@ class _CompatProperty(object):
if obj is None:
return self
from _pytest.deprecated import COMPAT_PROPERTY
warnings.warn(
"usage of {owner}.{name} is deprecated, please use pytest.{name} instead".format(
name=self.name, owner=owner.__name__
RemovedInPytest4Warning(
COMPAT_PROPERTY.format(name=self.name, owner=owner.__name__)
),
RemovedInPytest4Warning,
stacklevel=2,
)
return getattr(__import__("pytest"), self.name)
@ -129,14 +130,14 @@ class Node(object):
if isinstance(maybe_compatprop, _CompatProperty):
return getattr(__import__("pytest"), name)
else:
from _pytest.deprecated import CUSTOM_CLASS
cls = getattr(self, name)
msg = (
'use of special named "%s" objects in collectors of type "%s" to '
"customize the created nodes is deprecated. "
"Use pytest_pycollect_makeitem(...) to create custom "
"collection nodes instead." % (name, type(self).__name__)
self.warn(
RemovedInPytest4Warning(
CUSTOM_CLASS.format(name=name, type_name=type(self).__name__)
)
)
self.warn(RemovedInPytest4Warning(msg))
return cls
def __repr__(self):