[WIP] Update warning stacklevel when wrapping warnings.warn
This commit is contained in:
parent
7931b5b489
commit
1b51497936
|
@ -156,6 +156,8 @@ class WarningsRecorder(warnings.catch_warnings):
|
||||||
if six.PY2:
|
if six.PY2:
|
||||||
|
|
||||||
def warn(*args, **kwargs):
|
def warn(*args, **kwargs):
|
||||||
|
kwargs.setdefault("stacklevel", 1)
|
||||||
|
kwargs["stacklevel"] += 1
|
||||||
return self._saved_warn(*args, **kwargs)
|
return self._saved_warn(*args, **kwargs)
|
||||||
|
|
||||||
warnings.warn, self._saved_warn = warn, warnings.warn
|
warnings.warn, self._saved_warn = warn, warnings.warn
|
||||||
|
|
|
@ -6,6 +6,12 @@ import pytest
|
||||||
from _pytest.recwarn import WarningsRecorder
|
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):
|
def test_recwarn_functional(testdir):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue