Merge pull request #2120 from RonnyPfannschmidt/fix-2118

fix #2118 - rework Node._getcustomclass and Node compat properties
This commit is contained in:
Bruno Oliveira 2017-01-20 14:38:55 -02:00 committed by GitHub
commit 15a3b57ec7
2 changed files with 35 additions and 19 deletions

View File

@ -1,7 +1,10 @@
3.0.6.dev0 (unreleased) 3.0.6.dev0 (unreleased)
======================= =======================
* * pytest no longer generates ``PendingDeprecationWarning`` from its own operations, which was introduced by mistake in version ``3.0.5`` (`#2118`_).
Thanks to `@nicoddemus`_ for the report and `@RonnyPfannschmidt`_ for the PR.
* pytest no longer recognizes coroutine functions as yield tests (`#2129`_). * pytest no longer recognizes coroutine functions as yield tests (`#2129`_).
Thanks to `@malinoff`_ for the PR. Thanks to `@malinoff`_ for the PR.
@ -34,6 +37,7 @@
.. _@pelme: https://github.com/pelme .. _@pelme: https://github.com/pelme
.. _@eli-b: https://github.com/eli-b .. _@eli-b: https://github.com/eli-b
.. _#2118: https://github.com/pytest-dev/pytest/issues/2118
.. _#1989: https://github.com/pytest-dev/pytest/issues/1989 .. _#1989: https://github.com/pytest-dev/pytest/issues/1989
.. _#1920: https://github.com/pytest-dev/pytest/issues/1920 .. _#1920: https://github.com/pytest-dev/pytest/issues/1920

View File

@ -190,14 +190,22 @@ class FSHookProxy:
self.__dict__[name] = x self.__dict__[name] = x
return x return x
def compatproperty(name): class _CompatProperty(object):
def fget(self): def __init__(self, name):
import warnings self.name = name
warnings.warn("This usage is deprecated, please use pytest.{0} instead".format(name),
PendingDeprecationWarning, stacklevel=2) def __get__(self, obj, owner):
return getattr(pytest, name) 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)
return getattr(pytest, self.name)
return property(fget)
class NodeKeywords(MappingMixin): class NodeKeywords(MappingMixin):
def __init__(self, node): def __init__(self, node):
@ -269,19 +277,23 @@ class Node(object):
""" fspath sensitive hook proxy used to call pytest hooks""" """ fspath sensitive hook proxy used to call pytest hooks"""
return self.session.gethookproxy(self.fspath) return self.session.gethookproxy(self.fspath)
Module = compatproperty("Module") Module = _CompatProperty("Module")
Class = compatproperty("Class") Class = _CompatProperty("Class")
Instance = compatproperty("Instance") Instance = _CompatProperty("Instance")
Function = compatproperty("Function") Function = _CompatProperty("Function")
File = compatproperty("File") File = _CompatProperty("File")
Item = compatproperty("Item") Item = _CompatProperty("Item")
def _getcustomclass(self, name): def _getcustomclass(self, name):
cls = getattr(self, name) maybe_compatprop = getattr(type(self), name)
if cls != getattr(pytest, name): if isinstance(maybe_compatprop, _CompatProperty):
py.log._apiwarn("2.0", "use of node.%s is deprecated, " return getattr(pytest, name)
"use pytest_pycollect_makeitem(...) to create custom " else:
"collection nodes" % name) 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)
return cls return cls
def __repr__(self): def __repr__(self):