Skip to content

Commit e32b98f

Browse files
committed
Allow to disable unnecessary API registry checks via Django settings.NINJA_SKIP_REGISTRY
1 parent 9b7c4f1 commit e32b98f

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

ninja/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Union,
1414
)
1515

16+
from django.conf import settings
1617
from django.http import HttpRequest, HttpResponse
1718
from django.urls import URLPattern, URLResolver, reverse
1819
from django.utils.module_loading import import_string
@@ -561,7 +562,7 @@ def _lookup_exception_handler(self, exc: Exc[_E]) -> Optional[ExcHandler[_E]]:
561562

562563
def _validate(self) -> None:
563564
# urls namespacing validation
564-
skip_registry = os.environ.get("NINJA_SKIP_REGISTRY", False)
565+
skip_registry = getattr(settings, "NINJA_SKIP_REGISTRY", False)
565566
if (
566567
not skip_registry
567568
and self.urls_namespace in NinjaAPI._registry

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")
1111

1212
import django # noqa
13+
from django.conf import settings # noqa
1314

1415
django.setup()
1516

1617

1718
def pytest_generate_tests(metafunc):
18-
os.environ["NINJA_SKIP_REGISTRY"] = "yes"
19+
settings.NINJA_SKIP_REGISTRY = True

tests/test_app.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ def test_method(method, path, expected_status, expected_data, expected_streaming
102102
assert data == expected_data
103103

104104

105-
def test_validates():
106-
try:
107-
os.environ["NINJA_SKIP_REGISTRY"] = ""
108-
with pytest.raises(ConfigError):
109-
_urls = NinjaAPI().urls
110-
finally:
111-
os.environ["NINJA_SKIP_REGISTRY"] = "yes"
105+
def test_validates(settings):
106+
delattr(settings, "NINJA_SKIP_REGISTRY")
107+
with pytest.raises(ConfigError):
108+
_urls = NinjaAPI().urls

0 commit comments

Comments
 (0)