Skip to content

Commit 1d92601

Browse files
add deprecation warnings for using markinfo attributes
1 parent c791895 commit 1d92601

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

_pytest/deprecated.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
"""
88
from __future__ import absolute_import, division, print_function
99

10+
11+
class RemovedInPytest4_0Warning(DeprecationWarning):
12+
"warning class for features removed in pytest 4.0"
13+
14+
1015
MAIN_STR_ARGS = 'passing a string to pytest.main() is deprecated, ' \
1116
'pass a list of arguments instead.'
1217

@@ -22,3 +27,6 @@
2227
GETFUNCARGVALUE = "use of getfuncargvalue is deprecated, use getfixturevalue"
2328

2429
RESULT_LOG = '--result-log is deprecated and scheduled for removal in pytest 4.0'
30+
31+
MARK_INFO_ATTRIBUTE = RemovedInPytest4_0Warning(
32+
"Markinfo attributes are deprecated, please iterate the mark Collection")

_pytest/mark.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
from __future__ import absolute_import, division, print_function
33

44
import inspect
5+
import warnings
56
from collections import namedtuple
67
from operator import attrgetter
78
from .compat import imap
9+
from .deprecated import MARK_INFO_ATTRIBUTE
810

11+
def alias(name, warning=None):
12+
getter = attrgetter(name)
913

10-
def alias(name):
11-
# todo: introduce deprecationwarnings
12-
return property(attrgetter(name), doc='alias for ' + name)
14+
def warned(self):
15+
warnings.warn(warning, stacklevel=2)
16+
return getter(self)
17+
18+
return property(getter if warning is None else warned, doc='alias for ' + name)
1319

1420

1521
class ParameterSet(namedtuple('ParameterSet', 'values, marks, id')):
@@ -382,9 +388,9 @@ def __init__(self, mark):
382388
self.combined = mark
383389
self._marks = [mark]
384390

385-
name = alias('combined.name')
386-
args = alias('combined.args')
387-
kwargs = alias('combined.kwargs')
391+
name = alias('combined.name', warning=MARK_INFO_ATTRIBUTE)
392+
args = alias('combined.args', warning=MARK_INFO_ATTRIBUTE)
393+
kwargs = alias('combined.kwargs', warning=MARK_INFO_ATTRIBUTE)
388394

389395
def __repr__(self):
390396
return "<MarkInfo {0!r}>".format(self.combined)

0 commit comments

Comments
 (0)