Skip to content

Commit

Permalink
intermediate followup for pytest-dev#2452 - warn about getcustomclass…
Browse files Browse the repository at this point in the history
… again
  • Loading branch information
RonnyPfannschmidt committed Aug 16, 2017
1 parent 5c0feb2 commit 568b3c9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
15 changes: 15 additions & 0 deletions _pytest/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
18 changes: 8 additions & 10 deletions _pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import absolute_import, division, print_function

import functools
import warnings
import os
import six
import sys
Expand All @@ -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
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 568b3c9

Please sign in to comment.