From 32ee0b9c885d8bdda9edeabd86277ba1cb31dce4 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 13 Sep 2018 15:56:50 -0300 Subject: [PATCH] Move warning messages to _pytest.deprecated --- src/_pytest/deprecated.py | 16 ++++++++++++++++ src/_pytest/fixtures.py | 8 +++----- src/_pytest/nodes.py | 19 ++++++++++--------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index dea8bbde8..5c98fd43c 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -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. " diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index f2c8085ed..610907342 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -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) diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index 8fc11eb4c..287bd4181 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -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):