added explicit check for necessary env vars
Code Quality Pipeline / Check Code (pull_request) Failing after 3m7s

This commit is contained in:
brian
2025-03-17 22:19:14 +00:00
parent 400706e730
commit ad82ad4591
@@ -37,10 +37,12 @@ if test_env_path.exists():
load_dotenv(test_env_path.as_posix())
# define test environment variables
assert 'MINIO_ENDPOINT' in os.environ, 'MINIO_ENDPOINT not set'
assert 'MINIO_ACCESS_KEY' in os.environ, 'MINIO_ACCESS_KEY not set'
assert 'MINIO_SECRET_KEY' in os.environ, 'MINIO_SECRET_KEY not set'
assert 'MONGO_ENDPOINT' in os.environ, 'MONGO_ENDPOINT not set'
necessary_env_vars = {
'MINIO_ENDPOINT',
'MINIO_ACCESS_KEY',
'MINIO_SECRET_KEY',
'MONGO_ENDPOINT',
}
env_var_map = {
'MINIO_BUCKET_NAME': 'test-bucket',
'MINIO_OBJECT_NAME': 'test-object',
@@ -51,15 +53,15 @@ env_var_map = {
@pytest.fixture(scope='session', autouse=True)
def populate_env(
def setup_env(
request: pytest.FixtureRequest,
) -> None:
"""Populate environment with variables used for testing."""
# update env
# check if necessary env vars are set
for key in necessary_env_vars:
assert key in os.environ, f'{key} not set'
# set testing env vars
for key, val in env_var_map.items():
# skip if already set by CI pipeline
if key in os.environ:
continue
# set env var
os.environ[key] = val
@@ -73,7 +75,7 @@ def populate_env(
@pytest.fixture(scope='session')
def raw_minio_client(
populate_env,
setup_env,
) -> Iterator[minio.Minio]:
"""Raw Minio client fixture."""
# prepare arguments
@@ -105,7 +107,7 @@ def raw_minio_client(
@pytest.fixture
def minio_client(
populate_env,
setup_env,
) -> Iterator[MinioImplementation]:
"""MinioImplementation fixture."""
# instantiate and connect client
@@ -206,7 +208,7 @@ def image_data_in_minio(
@pytest.fixture(scope='session')
def image_repo(
populate_env,
setup_env,
) -> Iterator[ImageRepository]:
"""Image repository fixture."""
# define test environment variables
@@ -271,7 +273,7 @@ def model_data_in_minio(
@pytest.fixture(scope='session')
def model_repo(
populate_env,
setup_env,
) -> Iterator[ModelRepository]:
"""Model repository fixture."""
repo = ModelRepository()
@@ -282,7 +284,7 @@ def model_repo(
@pytest.fixture
def raw_mongo_client(
populate_env,
setup_env,
) -> Iterator[MongoClient]:
"""Raw mongo client fixture."""
# prepare arguments
@@ -299,7 +301,7 @@ def raw_mongo_client(
@pytest.fixture
def mongo_client(
populate_env,
setup_env,
) -> Iterator[MongoImplementation]:
"""MongoImplementation fixture."""
# instantiate and connect client
@@ -394,7 +396,7 @@ def visual_communication_data_in_mongo(
@pytest.fixture(scope='session')
def visual_communication_repo(
populate_env,
setup_env,
) -> Iterator[VisualCommunicationRepository]:
"""Visual communication repository fixture."""
repo = VisualCommunicationRepository()