diff --git a/sanic/base.py b/sanic/base.py index fd33838f..ff4833fa 100644 --- a/sanic/base.py +++ b/sanic/base.py @@ -36,7 +36,7 @@ class BaseSanic( warn( f"{class_name} instance named '{name}' uses a format that is" 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, ) diff --git a/tests/conftest.py b/tests/conftest.py index 70d97573..65b218cf 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -15,6 +15,7 @@ from sanic.constants import HTTP_METHODS from sanic.router import Router +slugify = re.compile(r"[^a-zA-Z0-9_\-]") random.seed("Pack my box with five dozen liquor jugs.") Sanic.test_mode = True @@ -140,5 +141,5 @@ def url_param_generator(): @pytest.fixture(scope="function") def app(request): - app = Sanic(request.node.name) + app = Sanic(slugify.sub("-", request.node.name)) return app diff --git a/tests/test_base.py b/tests/test_base.py index 72567621..11d275a1 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -78,11 +78,25 @@ def test_names_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) - with pytest.warns(DeprecationWarning): + with pytest.warns(DeprecationWarning) as bp_e: bp = Blueprint(name) assert app.name == name assert bp.name == name + + assert app_e[0].message.args[0] == app_message + assert bp_e[0].message.args[0] == bp_message