Skip to content

Fixed#2684: use the correct stacklevel for deprecation warnings #2689

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def __init__(self, *names, **attrs):
'pytest now uses argparse. "%default" should be'
' changed to "%(default)s" ',
DeprecationWarning,
stacklevel=3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change looks incorrect, the argument type is used indirectly and the higher level intended to trigger that warning for the method call side

stacklevel=2)
try:
typ = attrs['type']
except KeyError:
Expand All @@ -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])
Expand All @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion _pytest/mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case stacklevel is also not usable, its a case where its probably more sensible to warn explicit and pass the test around


return cls(argval, marks=newmarks, id=None)

Expand Down
2 changes: 1 addition & 1 deletion _pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this one stacklevel is actually not applicable

if s:
return _ascii_escaped(s)

Expand Down