From 0387829c8c676fd2558f0768fb45368c275535b7 Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Wed, 16 Aug 2017 00:28:43 +0530 Subject: [PATCH] use the correct stacklevel for deprecation warnings --- _pytest/config.py | 6 +++--- _pytest/mark.py | 2 +- _pytest/python.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/_pytest/config.py b/_pytest/config.py index 364ac13c6b2..b96ba3750a5 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -636,7 +636,7 @@ def __init__(self, *names, **attrs): 'pytest now uses argparse. "%default" should be' ' changed to "%(default)s" ', DeprecationWarning, - stacklevel=3) + stacklevel=2) try: typ = attrs['type'] except KeyError: @@ -651,7 +651,7 @@ def __init__(self, *names, **attrs): ' should be a type.' ' (options: %s)' % (typ, names), DeprecationWarning, - stacklevel=3) + stacklevel=2) # argparse expects a type here take it from # the type of the first element attrs['type'] = type(attrs['choices'][0]) @@ -661,7 +661,7 @@ def __init__(self, *names, **attrs): ' For parsearg this should be a type.' ' (options: %s)' % (typ, names), DeprecationWarning, - stacklevel=3) + stacklevel=2) attrs['type'] = Argument._typ_map[typ] # used in test_parseopt -> test_parse_defaultgetter self.type = attrs['type'] diff --git a/_pytest/mark.py b/_pytest/mark.py index 74473a9d78a..3f3b70b1fc0 100644 --- a/_pytest/mark.py +++ b/_pytest/mark.py @@ -63,7 +63,7 @@ def extract_from(cls, parameterset, legacy_force_tuple=False): argval = argval, if newmarks: - warnings.warn(MARK_PARAMETERSET_UNPACKING) + warnings.warn(MARK_PARAMETERSET_UNPACKING, stacklevel=2) return cls(argval, marks=newmarks, id=None) diff --git a/_pytest/python.py b/_pytest/python.py index e7bb9ad62d5..108152ad84a 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -919,7 +919,7 @@ def _idval(val, argname, idx, idfn, config=None): import warnings msg = "Raised while trying to determine id of parameter %s at position %d." % (argname, idx) msg += '\nUpdate your code as this will raise an error in pytest-4.0.' - warnings.warn(msg, DeprecationWarning) + warnings.warn(msg, DeprecationWarning, stacklevel=2) if s: return _ascii_escaped(s)