Skip to content

Commit 2424242

Browse files
GitHKAndrei Neagusanderegg
authored
faster webserver with_dbs tests (ITISFoundation#2467)
Co-authored-by: Andrei Neagu <[email protected]> Co-authored-by: Sylvain <[email protected]>
1 parent f90894b commit 2424242

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

services/web/server/src/simcore_service_webserver/rest.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
"""
88
import logging
9+
from functools import lru_cache
910
from pathlib import Path
1011
from typing import Optional
1112

@@ -14,7 +15,6 @@
1415
from aiohttp import web
1516
from aiohttp_swagger import setup_swagger
1617
from openapi_core.schema.specs.models import Spec as OpenApiSpecs
17-
1818
from servicelib import openapi
1919
from servicelib.application_setup import ModuleCategory, app_module_setup
2020
from servicelib.rest_middlewares import (
@@ -25,8 +25,8 @@
2525

2626
from . import rest_routes
2727
from ._meta import api_version_prefix
28-
from .rest_config import APP_OPENAPI_SPECS_KEY, assert_valid_config
2928
from .diagnostics_config import get_diagnostics_config
29+
from .rest_config import APP_OPENAPI_SPECS_KEY, assert_valid_config
3030

3131
log = logging.getLogger(__name__)
3232

@@ -38,6 +38,7 @@ def get_openapi_specs_path(api_version_dir: Optional[str] = None) -> Path:
3838
return resources.get_path(f"api/{api_version_dir}/openapi.yaml")
3939

4040

41+
@lru_cache # required to boost tests speed, gains 3.5s per test
4142
def load_openapi_specs(spec_path: Optional[Path] = None) -> OpenApiSpecs:
4243
if spec_path is None:
4344
spec_path = get_openapi_specs_path()
@@ -116,4 +117,4 @@ def setup(app: web.Application, *, swagger_doc_enabled: bool = True):
116117
# alias
117118
setup_rest = setup
118119

119-
__all__ = "setup_rest"
120+
__all__ = ["setup_rest"]

services/web/server/tests/unit/with_dbs/conftest.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from importlib import reload
1818
from pathlib import Path
1919
from typing import Callable, Dict, Iterator, List
20+
from unittest.mock import patch
2021
from uuid import uuid4
2122

2223
import aioredis
@@ -33,9 +34,10 @@
3334
from pytest_simcore.helpers.utils_login import NewUser
3435
from servicelib.aiopg_utils import DSN
3536
from servicelib.application_keys import APP_CONFIG_KEY, APP_DB_ENGINE_KEY
37+
from simcore_service_webserver import rest
3638
from simcore_service_webserver.application import create_application
3739
from simcore_service_webserver.application_config import app_schema as app_schema
38-
from simcore_service_webserver.constants import APP_DB_ENGINE_KEY, INDEX_RESOURCE_NAME
40+
from simcore_service_webserver.constants import INDEX_RESOURCE_NAME
3941
from simcore_service_webserver.groups_api import (
4042
add_user_in_group,
4143
create_user_group,
@@ -51,6 +53,17 @@
5153
# DEPLOYED SERVICES FOR TESTSUITE SESSION -----------------------------------
5254

5355

56+
@pytest.fixture(autouse=True)
57+
def disable_swagger_doc_genertion() -> None:
58+
"""
59+
by not enabling the swagger documentation, 1.8s per test is gained
60+
"""
61+
with patch.dict(
62+
rest.setup.__wrapped__.__kwdefaults__, {"swagger_doc_enabled": False}
63+
):
64+
yield
65+
66+
5467
@pytest.fixture(scope="session")
5568
def default_app_cfg(osparc_simcore_root_dir):
5669
# NOTE: ONLY used at the session scopes

0 commit comments

Comments
 (0)