Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1989 Add disable app registry #1993

Merged
merged 7 commits into from Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion sanic/app.py
Expand Up @@ -50,6 +50,7 @@ def __init__(
strict_slashes=False,
log_config=None,
configure_logging=True,
register=None,
):

# Get name from previous stack frame
Expand Down Expand Up @@ -88,7 +89,11 @@ def __init__(
# Register alternative method names
self.go_fast = self.run

self.__class__.register_app(self)
if register is not None:
self.config.REGISTER = register

if self.config.REGISTER:
self.__class__.register_app(self)

@property
def loop(self):
Expand Down
1 change: 1 addition & 0 deletions sanic/config.py
Expand Up @@ -40,6 +40,7 @@
"PROXIES_COUNT": None,
"FORWARDED_FOR_HEADER": "X-Forwarded-For",
"FALLBACK_ERROR_FORMAT": "html",
"REGISTER": True,
}


Expand Down
16 changes: 16 additions & 0 deletions tests/test_app.py
Expand Up @@ -3,6 +3,7 @@
import sys

from inspect import isawaitable
from os import environ
from unittest.mock import patch

import pytest
Expand Down Expand Up @@ -290,6 +291,7 @@ def test_app_registry_name_reuse():
with pytest.raises(SanicException):
Sanic("test")
Sanic.test_mode = True
Sanic("test")


def test_app_registry_retrieval():
Expand All @@ -306,3 +308,17 @@ def test_get_app_does_not_exist_force_create():
assert isinstance(
Sanic.get_app("does-not-exist", force_create=True), Sanic
)


def test_app_no_registry():
Sanic("no-register", register=False)
with pytest.raises(SanicException):
Sanic.get_app("no-register")


def test_app_no_registry_env():
environ["SANIC_REGISTER"] = "False"
Sanic("no-register")
with pytest.raises(SanicException):
Sanic.get_app("no-register")
del environ["SANIC_REGISTER"]