Add deprecation warning filter (#2546)

This commit is contained in:
Adam Hopkins
2022-09-18 18:54:35 +03:00
committed by GitHub
parent 4726cf1910
commit 7f894c45b3
3 changed files with 40 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
import pytest
from sanic import Sanic
from sanic.log import deprecation
@@ -7,3 +8,13 @@ def test_deprecation():
message = r"\[DEPRECATION v9\.9\] hello"
with pytest.warns(DeprecationWarning, match=message):
deprecation("hello", 9.9)
@pytest.mark.parametrize(
"filter,expected",
(("default", 1), ("once", 1), ("ignore", 0)),
)
def test_deprecation_filter(app: Sanic, filter, expected, recwarn):
app.config.DEPRECATION_FILTER = filter
deprecation("hello", 9.9)
assert len(recwarn) == expected