From 1d926011a4d684c4bd505a3e7ecc444f43cdc446 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Thu, 22 Jun 2017 15:12:50 +0200 Subject: [PATCH] add deprecation warnings for using markinfo attributes --- _pytest/deprecated.py | 8 ++++++++ _pytest/mark.py | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/_pytest/deprecated.py b/_pytest/deprecated.py index e75ff099e..44af1b48e 100644 --- a/_pytest/deprecated.py +++ b/_pytest/deprecated.py @@ -7,6 +7,11 @@ be removed when the time comes. """ 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, ' \ '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" 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") \ No newline at end of file diff --git a/_pytest/mark.py b/_pytest/mark.py index 08a0bd164..a3f84867e 100644 --- a/_pytest/mark.py +++ b/_pytest/mark.py @@ -2,14 +2,20 @@ from __future__ import absolute_import, division, print_function import inspect +import warnings from collections import namedtuple from operator import attrgetter from .compat import imap +from .deprecated import MARK_INFO_ATTRIBUTE +def alias(name, warning=None): + getter = attrgetter(name) -def alias(name): - # todo: introduce deprecationwarnings - return property(attrgetter(name), doc='alias for ' + name) + def warned(self): + warnings.warn(warning, stacklevel=2) + return getter(self) + + return property(getter if warning is None else warned, doc='alias for ' + name) class ParameterSet(namedtuple('ParameterSet', 'values, marks, id')): @@ -382,9 +388,9 @@ class MarkInfo(object): self.combined = mark self._marks = [mark] - name = alias('combined.name') - args = alias('combined.args') - kwargs = alias('combined.kwargs') + name = alias('combined.name', warning=MARK_INFO_ATTRIBUTE) + args = alias('combined.args', warning=MARK_INFO_ATTRIBUTE) + kwargs = alias('combined.kwargs', warning=MARK_INFO_ATTRIBUTE) def __repr__(self): return "".format(self.combined)