added explicit check for necessary env vars
Code Quality Pipeline / Check Code (pull_request) Failing after 3m7s
Code Quality Pipeline / Check Code (pull_request) Failing after 3m7s
This commit is contained in:
@@ -37,10 +37,12 @@ if test_env_path.exists():
|
|||||||
load_dotenv(test_env_path.as_posix())
|
load_dotenv(test_env_path.as_posix())
|
||||||
|
|
||||||
# define test environment variables
|
# define test environment variables
|
||||||
assert 'MINIO_ENDPOINT' in os.environ, 'MINIO_ENDPOINT not set'
|
necessary_env_vars = {
|
||||||
assert 'MINIO_ACCESS_KEY' in os.environ, 'MINIO_ACCESS_KEY not set'
|
'MINIO_ENDPOINT',
|
||||||
assert 'MINIO_SECRET_KEY' in os.environ, 'MINIO_SECRET_KEY not set'
|
'MINIO_ACCESS_KEY',
|
||||||
assert 'MONGO_ENDPOINT' in os.environ, 'MONGO_ENDPOINT not set'
|
'MINIO_SECRET_KEY',
|
||||||
|
'MONGO_ENDPOINT',
|
||||||
|
}
|
||||||
env_var_map = {
|
env_var_map = {
|
||||||
'MINIO_BUCKET_NAME': 'test-bucket',
|
'MINIO_BUCKET_NAME': 'test-bucket',
|
||||||
'MINIO_OBJECT_NAME': 'test-object',
|
'MINIO_OBJECT_NAME': 'test-object',
|
||||||
@@ -51,15 +53,15 @@ env_var_map = {
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session', autouse=True)
|
@pytest.fixture(scope='session', autouse=True)
|
||||||
def populate_env(
|
def setup_env(
|
||||||
request: pytest.FixtureRequest,
|
request: pytest.FixtureRequest,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Populate environment with variables used for testing."""
|
"""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():
|
for key, val in env_var_map.items():
|
||||||
# skip if already set by CI pipeline
|
|
||||||
if key in os.environ:
|
|
||||||
continue
|
|
||||||
# set env var
|
# set env var
|
||||||
os.environ[key] = val
|
os.environ[key] = val
|
||||||
|
|
||||||
@@ -73,7 +75,7 @@ def populate_env(
|
|||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def raw_minio_client(
|
def raw_minio_client(
|
||||||
populate_env,
|
setup_env,
|
||||||
) -> Iterator[minio.Minio]:
|
) -> Iterator[minio.Minio]:
|
||||||
"""Raw Minio client fixture."""
|
"""Raw Minio client fixture."""
|
||||||
# prepare arguments
|
# prepare arguments
|
||||||
@@ -105,7 +107,7 @@ def raw_minio_client(
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def minio_client(
|
def minio_client(
|
||||||
populate_env,
|
setup_env,
|
||||||
) -> Iterator[MinioImplementation]:
|
) -> Iterator[MinioImplementation]:
|
||||||
"""MinioImplementation fixture."""
|
"""MinioImplementation fixture."""
|
||||||
# instantiate and connect client
|
# instantiate and connect client
|
||||||
@@ -206,7 +208,7 @@ def image_data_in_minio(
|
|||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def image_repo(
|
def image_repo(
|
||||||
populate_env,
|
setup_env,
|
||||||
) -> Iterator[ImageRepository]:
|
) -> Iterator[ImageRepository]:
|
||||||
"""Image repository fixture."""
|
"""Image repository fixture."""
|
||||||
# define test environment variables
|
# define test environment variables
|
||||||
@@ -271,7 +273,7 @@ def model_data_in_minio(
|
|||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def model_repo(
|
def model_repo(
|
||||||
populate_env,
|
setup_env,
|
||||||
) -> Iterator[ModelRepository]:
|
) -> Iterator[ModelRepository]:
|
||||||
"""Model repository fixture."""
|
"""Model repository fixture."""
|
||||||
repo = ModelRepository()
|
repo = ModelRepository()
|
||||||
@@ -282,7 +284,7 @@ def model_repo(
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def raw_mongo_client(
|
def raw_mongo_client(
|
||||||
populate_env,
|
setup_env,
|
||||||
) -> Iterator[MongoClient]:
|
) -> Iterator[MongoClient]:
|
||||||
"""Raw mongo client fixture."""
|
"""Raw mongo client fixture."""
|
||||||
# prepare arguments
|
# prepare arguments
|
||||||
@@ -299,7 +301,7 @@ def raw_mongo_client(
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mongo_client(
|
def mongo_client(
|
||||||
populate_env,
|
setup_env,
|
||||||
) -> Iterator[MongoImplementation]:
|
) -> Iterator[MongoImplementation]:
|
||||||
"""MongoImplementation fixture."""
|
"""MongoImplementation fixture."""
|
||||||
# instantiate and connect client
|
# instantiate and connect client
|
||||||
@@ -394,7 +396,7 @@ def visual_communication_data_in_mongo(
|
|||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def visual_communication_repo(
|
def visual_communication_repo(
|
||||||
populate_env,
|
setup_env,
|
||||||
) -> Iterator[VisualCommunicationRepository]:
|
) -> Iterator[VisualCommunicationRepository]:
|
||||||
"""Visual communication repository fixture."""
|
"""Visual communication repository fixture."""
|
||||||
repo = VisualCommunicationRepository()
|
repo = VisualCommunicationRepository()
|
||||||
|
|||||||
Reference in New Issue
Block a user