-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Changes from 1 commit
9c285df
4082f40
7b4afd8
6a96b46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
import os | ||
import sys | ||
|
||
import warnings | ||
|
||
import _pytest | ||
import _pytest._code | ||
import py | ||
|
@@ -190,14 +192,21 @@ 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 | ||
|
||
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): | ||
|
@@ -269,19 +278,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, " | ||
maybe_compatprop = getattr(type(self), name) | ||
if isinstance(maybe_compatprop, _CompatProperty): | ||
return getattr(pytest, name) | ||
else: | ||
cls = getattr(self, name) | ||
|
||
warnings.warn("use of node.%s is deprecated, " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is different use-cases there one warns about using the attributes, the other warns about custom declarations while still supporting them custom declarations will override the properties the coode i posted ensures that
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's a "custom declaration" in this context exactly? Subclassing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct, py.test previously used classes and attributes in the 1.x series |
||
"use pytest_pycollect_makeitem(...) to create custom " | ||
"collection nodes" % name) | ||
"collection nodes" % name, category=DeprecationWarning) | ||
return cls | ||
|
||
def __repr__(self): | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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: