File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed
packages/pytest-simcore/src/pytest_simcore
services/api-server/tests/unit Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change 33# pylint: disable=unused-variable
44
55
6+ import logging
67import re
78from pathlib import Path
89from typing import Any
1213from .helpers .monkeypatch_envs import load_dotenv , setenvs_from_dict
1314from .helpers .typing_env import EnvVarsDict
1415
16+ _logger = logging .getLogger (__name__ )
17+
1518
1619def pytest_addoption (parser : pytest .Parser ):
1720 simcore_group = parser .getgroup ("simcore" )
@@ -35,12 +38,20 @@ def external_envfile_dict(request: pytest.FixtureRequest) -> EnvVarsDict:
3538 """
3639 envs = {}
3740 if envfile := request .config .getoption ("--external-envfile" ):
38- print ("🚨 EXTERNAL `envfile` option detected. Loading" , envfile , "..." )
41+ _logger .warning (
42+ "🚨 EXTERNAL `envfile` option detected. Loading '%s' ..." , envfile
43+ )
3944
4045 assert isinstance (envfile , Path )
4146 assert envfile .exists ()
4247 assert envfile .is_file ()
4348
49+ if not any (term in envfile .name .lower () for term in ("ignore" , "secret" )):
50+ _logger .warning (
51+ "🚨 CAUTION: The provided envfile '%s' might be pushed in this repository. Please rename it with `secret` or `ignore`" ,
52+ envfile .name ,
53+ )
54+
4455 envs = load_dotenv (envfile )
4556
4657 return envs
Original file line number Diff line number Diff line change @@ -23,7 +23,6 @@ def app_environment(
2323
2424 ln -s /path/to/osparc-config/deployments/mydeploy.com/repo.config .secrets
2525 pytest --external-envfile=.secrets tests/unit/test_core_settings.py
26-
2726 """
2827 if external_envfile_dict :
2928 delenvs_from_dict (monkeypatch , app_environment , raising = False )
@@ -34,7 +33,17 @@ def app_environment(
3433 return app_environment
3534
3635
37- def test_unit_app_environment (app_environment : EnvVarsDict ):
36+ def test_valid_application_settings (app_environment : EnvVarsDict ):
37+ """
38+ We can validate actual .env files (also refered as `repo.config` files) by passing them via the CLI
39+
40+ $ ln -s /path/to/osparc-config/deployments/mydeploy.com/repo.config .secrets
41+ $ pytest --external-envfile=.secrets --pdb tests/unit/test_core_settings.py
42+
43+ """
3844 assert app_environment
39- settings = ApplicationSettings .create_from_envs ()
40- print ("captured settings: \n " , settings .model_dump_json (indent = 2 ))
45+
46+ settings = ApplicationSettings () # type: ignore
47+ assert settings
48+
49+ assert settings == ApplicationSettings .create_from_envs ()
You can’t perform that action at this time.
0 commit comments