From 568b3c9efed965ce7858a1bd3809750e70c03482 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Wed, 16 Aug 2017 16:29:31 +0200 Subject: [PATCH] intermediate followup for #2452 - warn about getcustomclass again --- _pytest/deprecated.py | 15 +++++++++++++++ _pytest/main.py | 18 ++++++++---------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/_pytest/deprecated.py b/_pytest/deprecated.py index 4f7b9e9361e..f657472f9ca 100644 --- a/_pytest/deprecated.py +++ b/_pytest/deprecated.py @@ -37,3 +37,18 @@ class RemovedInPytest4Warning(DeprecationWarning): " please use pytest.param(..., marks=...) instead.\n" "For more details, see: https://docs.pytest.org/en/latest/parametrize.html" ) + + +def node_customclass_warning(name): + return RemovedInPytest4Warning( + "use of node.{name} is deprecated, " + "use pytest_pycollect_makeitem(...) to create custom " + "collection nodes".format(name=name) + ) + + +def node_class_use_pytest_instead_warning(owner, name): + return RemovedInPytest4Warning( + "usage of {owner!r}.{name} is deprecated, " + "please use pytest.{name} instead".format( + name=name, owner=type(owner).__name__)) \ No newline at end of file diff --git a/_pytest/main.py b/_pytest/main.py index f05cb7ff3b3..122f88612ae 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -2,6 +2,7 @@ from __future__ import absolute_import, division, print_function import functools +import warnings import os import six import sys @@ -14,6 +15,7 @@ except ImportError: from UserDict import DictMixin as MappingMixin +from _pytest import deprecated from _pytest.config import directory_arg, UsageError, hookimpl from _pytest.runner import collect_one_node from _pytest.outcomes import exit @@ -220,12 +222,8 @@ def __init__(self, name): def __get__(self, obj, owner): if obj is None: return self - - # TODO: reenable in the features branch - # warnings.warn( - # "usage of {owner!r}.{name} is deprecated, please use pytest.{name} instead".format( - # name=self.name, owner=type(owner).__name__), - # PendingDeprecationWarning, stacklevel=2) + warnings.warn(deprecated.node_class_use_pytest_instead_warning( + owner=owner, name=self.name), stacklevel=2) return getattr(__import__('pytest'), self.name) @@ -308,14 +306,14 @@ def ihook(self): def _getcustomclass(self, name): maybe_compatprop = getattr(type(self), name) + warnings.warn(str(maybe_compatprop), category=UserWarning) if isinstance(maybe_compatprop, _CompatProperty): return getattr(__import__('pytest'), name) else: cls = getattr(self, name) - # TODO: reenable in the features branch - # warnings.warn("use of node.%s is deprecated, " - # "use pytest_pycollect_makeitem(...) to create custom " - # "collection nodes" % name, category=DeprecationWarning) + # OPTIONAL TODO: find a way to show the definition location + # of the class that owns that attribute + warnings.warn(deprecated.node_customclass_warning(name)) return cls def __repr__(self):