Cleanup conftest and fix warning message (#2147)

This commit is contained in:
Adam Hopkins 2021-05-31 22:41:41 +03:00 committed by GitHub
parent 680484bdc8
commit d16b9e5a02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View File

@ -36,7 +36,7 @@ class BaseSanic(
warn( warn(
f"{class_name} instance named '{name}' uses a format that is" f"{class_name} instance named '{name}' uses a format that is"
f"deprecated. Starting in version 21.12, {class_name} objects " f"deprecated. Starting in version 21.12, {class_name} objects "
"be named only using alphanumeric characters, _, or -.", "must be named only using alphanumeric characters, _, or -.",
DeprecationWarning, DeprecationWarning,
) )

View File

@ -15,6 +15,7 @@ from sanic.constants import HTTP_METHODS
from sanic.router import Router from sanic.router import Router
slugify = re.compile(r"[^a-zA-Z0-9_\-]")
random.seed("Pack my box with five dozen liquor jugs.") random.seed("Pack my box with five dozen liquor jugs.")
Sanic.test_mode = True Sanic.test_mode = True
@ -140,5 +141,5 @@ def url_param_generator():
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
def app(request): def app(request):
app = Sanic(request.node.name) app = Sanic(slugify.sub("-", request.node.name))
return app return app

View File

@ -78,11 +78,25 @@ def test_names_okay(name):
), ),
) )
def test_names_not_okay(name): def test_names_not_okay(name):
with pytest.warns(DeprecationWarning): app_message = (
f"Sanic instance named '{name}' uses a format that isdeprecated. "
"Starting in version 21.12, Sanic objects must be named only using "
"alphanumeric characters, _, or -."
)
bp_message = (
f"Blueprint instance named '{name}' uses a format that isdeprecated. "
"Starting in version 21.12, Blueprint objects must be named only using "
"alphanumeric characters, _, or -."
)
with pytest.warns(DeprecationWarning) as app_e:
app = Sanic(name) app = Sanic(name)
with pytest.warns(DeprecationWarning): with pytest.warns(DeprecationWarning) as bp_e:
bp = Blueprint(name) bp = Blueprint(name)
assert app.name == name assert app.name == name
assert bp.name == name assert bp.name == name
assert app_e[0].message.args[0] == app_message
assert bp_e[0].message.args[0] == bp_message