add deprecation warnings for using markinfo attributes

This commit is contained in:
Ronny Pfannschmidt 2017-06-22 15:12:50 +02:00
parent c791895c93
commit 1d926011a4
2 changed files with 20 additions and 6 deletions

View File

@ -7,6 +7,11 @@ be removed when the time comes.
""" """
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
class RemovedInPytest4_0Warning(DeprecationWarning):
"warning class for features removed in pytest 4.0"
MAIN_STR_ARGS = 'passing a string to pytest.main() is deprecated, ' \ MAIN_STR_ARGS = 'passing a string to pytest.main() is deprecated, ' \
'pass a list of arguments instead.' 'pass a list of arguments instead.'
@ -22,3 +27,6 @@ SETUP_CFG_PYTEST = '[pytest] section in setup.cfg files is deprecated, use [tool
GETFUNCARGVALUE = "use of getfuncargvalue is deprecated, use getfixturevalue" GETFUNCARGVALUE = "use of getfuncargvalue is deprecated, use getfixturevalue"
RESULT_LOG = '--result-log is deprecated and scheduled for removal in pytest 4.0' RESULT_LOG = '--result-log is deprecated and scheduled for removal in pytest 4.0'
MARK_INFO_ATTRIBUTE = RemovedInPytest4_0Warning(
"Markinfo attributes are deprecated, please iterate the mark Collection")

View File

@ -2,14 +2,20 @@
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
import inspect import inspect
import warnings
from collections import namedtuple from collections import namedtuple
from operator import attrgetter from operator import attrgetter
from .compat import imap from .compat import imap
from .deprecated import MARK_INFO_ATTRIBUTE
def alias(name, warning=None):
getter = attrgetter(name)
def alias(name): def warned(self):
# todo: introduce deprecationwarnings warnings.warn(warning, stacklevel=2)
return property(attrgetter(name), doc='alias for ' + name) return getter(self)
return property(getter if warning is None else warned, doc='alias for ' + name)
class ParameterSet(namedtuple('ParameterSet', 'values, marks, id')): class ParameterSet(namedtuple('ParameterSet', 'values, marks, id')):
@ -382,9 +388,9 @@ class MarkInfo(object):
self.combined = mark self.combined = mark
self._marks = [mark] self._marks = [mark]
name = alias('combined.name') name = alias('combined.name', warning=MARK_INFO_ATTRIBUTE)
args = alias('combined.args') args = alias('combined.args', warning=MARK_INFO_ATTRIBUTE)
kwargs = alias('combined.kwargs') kwargs = alias('combined.kwargs', warning=MARK_INFO_ATTRIBUTE)
def __repr__(self): def __repr__(self):
return "<MarkInfo {0!r}>".format(self.combined) return "<MarkInfo {0!r}>".format(self.combined)