Skip to content

Commit

Permalink
Merge pull request #2120 from RonnyPfannschmidt/fix-2118
Browse files Browse the repository at this point in the history
fix #2118 - rework Node._getcustomclass and Node compat properties
  • Loading branch information
nicoddemus authored Jan 20, 2017
2 parents 1a2d638 + 6a96b46 commit 15a3b57
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
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`_).
Thanks to `@malinoff`_ for the PR.
Expand Down Expand Up @@ -34,6 +37,7 @@
.. _@pelme: https://github.com/pelme
.. _@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
.. _#1920: https://github.com/pytest-dev/pytest/issues/1920
Expand Down
48 changes: 30 additions & 18 deletions _pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,22 @@ def __getattr__(self, name):
self.__dict__[name] = x
return x

def compatproperty(name):
def fget(self):
import warnings
warnings.warn("This usage is deprecated, please use pytest.{0} instead".format(name),
PendingDeprecationWarning, stacklevel=2)
return getattr(pytest, name)
class _CompatProperty(object):
def __init__(self, name):
self.name = 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)
return getattr(pytest, self.name)


return property(fget)

class NodeKeywords(MappingMixin):
def __init__(self, node):
Expand Down Expand Up @@ -269,19 +277,23 @@ def ihook(self):
""" fspath sensitive hook proxy used to call pytest hooks"""
return self.session.gethookproxy(self.fspath)

Module = compatproperty("Module")
Class = compatproperty("Class")
Instance = compatproperty("Instance")
Function = compatproperty("Function")
File = compatproperty("File")
Item = compatproperty("Item")
Module = _CompatProperty("Module")
Class = _CompatProperty("Class")
Instance = _CompatProperty("Instance")
Function = _CompatProperty("Function")
File = _CompatProperty("File")
Item = _CompatProperty("Item")

def _getcustomclass(self, name):
cls = getattr(self, name)
if cls != getattr(pytest, name):
py.log._apiwarn("2.0", "use of node.%s is deprecated, "
"use pytest_pycollect_makeitem(...) to create custom "
"collection nodes" % name)
maybe_compatprop = getattr(type(self), name)
if isinstance(maybe_compatprop, _CompatProperty):
return getattr(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)
return cls

def __repr__(self):
Expand Down

0 comments on commit 15a3b57

Please sign in to comment.