Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2118 - rework Node._getcustomclass and Node compat properties #2120

Merged
merged 4 commits into from
Jan 20, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
3.0.6.dev0
==========

*
* fix issue #2118 - protect against internal deprecationerrors by changing the code path of Node._getcustomclass.
Copy link
Member

@nicoddemus nicoddemus Dec 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a link to #2118?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RonnyPfannschmidt besides adding the link, I think it needs rewording to make more sense to users (which don't know about pytest's internals). Suggestion:

- 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.

This also turns a internal deprecation into a real deprecation.
Thanks to `@nicoddemus`_ for the report and `@RonnyPfannschmidt`_ for the PR.

*

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