[WIP] Update warning stacklevel when wrapping warnings.warn

This commit is contained in:
Ankit Goel 2018-10-18 02:36:41 +00:00
parent 7931b5b489
commit 1b51497936
2 changed files with 8 additions and 0 deletions

View File

@ -156,6 +156,8 @@ class WarningsRecorder(warnings.catch_warnings):
if six.PY2:
def warn(*args, **kwargs):
kwargs.setdefault("stacklevel", 1)
kwargs["stacklevel"] += 1
return self._saved_warn(*args, **kwargs)
warnings.warn, self._saved_warn = warn, warnings.warn

View File

@ -6,6 +6,12 @@ import pytest
from _pytest.recwarn import WarningsRecorder
def test_recwarn_stacklevel(recwarn):
warnings.warn("hello")
warn = recwarn.pop()
assert warn.filename == __file__
def test_recwarn_functional(testdir):
testdir.makepyfile(
"""