Skip to content

Commit e8d9f37

Browse files
committed
🐛 Improve logging for external envfile loading and rename test function for clarity
1 parent 3cbbd9d commit e8d9f37

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

packages/pytest-simcore/src/pytest_simcore/environment_configs.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# pylint: disable=unused-variable
44

55

6+
import logging
67
import re
78
from pathlib import Path
89
from typing import Any
@@ -12,6 +13,8 @@
1213
from .helpers.monkeypatch_envs import load_dotenv, setenvs_from_dict
1314
from .helpers.typing_env import EnvVarsDict
1415

16+
_logger = logging.getLogger(__name__)
17+
1518

1619
def 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

services/api-server/tests/unit/test_core_settings.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff 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()

0 commit comments

Comments
 (0)