Skip to content

Commit c3519fc

Browse files
committed
[DEV-12155] Ensure tests run on separate buckets than your local
1 parent 2b73730 commit c3519fc

3 files changed

Lines changed: 16 additions & 11 deletions

File tree

brus_backend_common/config.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ def JDBC_METASTORE_URL(self):
210210
MINIO_DATA_DIR: str = ""
211211

212212

213+
# TODO: Update CONFIG to use BaseModel with nested environment variables which can help generate this list automatically
214+
# (ex. BUCKETS__DATA_ARCHIVE -> CONFIG.BUCKETS.DATA_ARCHIVE)
215+
CONFIG_BUCKETS = [attr for attr, value in DefaultConfig().__dict__.items() if attr.endswith("_BUCKET")]
216+
217+
213218
def pull_ssm_config() -> dict:
214219
"""This function lives in the liminal space between CONFIG and helpers.aws, having a hand in both.
215220
While this is essentially more helpers.aws based, that file imports and uses CONFIG values from this file,
@@ -245,3 +250,11 @@ def set_brus_config(config: dict):
245250
if not CONFIG.IS_LOCAL:
246251
ssm_config = pull_ssm_config()
247252
CONFIG = DefaultConfig(**ssm_config)
253+
254+
# Overwrite any values if running in a test to prevent conflicting with your local environment
255+
# https://docs.pytest.org/en/stable/example/simple.html#detect-if-running-from-within-a-pytest-run
256+
if os.environ.get("PYTEST_VERSION") is not None:
257+
# Rename the buckets in the test environment to not overwrite your local buckets
258+
CONFIG = DefaultConfig(
259+
**{bucket_config: f"test-{getattr(CONFIG, bucket_config)}" for bucket_config in CONFIG_BUCKETS}
260+
)

brus_backend_common/models/__init__.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
from brus_backend_common.models.lakehouse_model import LakeHouseCurrentMigration, ExternalDataLoadDate
22

33
from brus_backend_common.models.reference import DEFCBronze, DEFCGold, DEFCGroup, FONBronze, FONGold
4-
from brus_backend_common.config import CONFIG
5-
6-
LAKEHOUSE_BUCKETS = {
7-
"broker": CONFIG.LAKEHOUSE_BROKER_BUCKET,
8-
"reference": CONFIG.LAKEHOUSE_REFERENCE_BUCKET,
9-
"usas": CONFIG.LAKEHOUSE_USAS_BUCKET,
10-
}
11-
LAKEHOUSE_BUCKET_NAMES = list(LAKEHOUSE_BUCKETS.values())
124

135
LAKEHOUSE_MODEL_CLASSES = [
146
DEFCBronze,

brus_backend_common/tests/conftest_spark.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
is_spark_context_stopped,
1111
stop_spark_context,
1212
)
13-
from brus_backend_common.config import CONFIG
13+
from brus_backend_common.config import CONFIG, CONFIG_BUCKETS
1414
from brus_backend_common.helpers.aws import _get_boto3
1515
from brus_backend_common.helpers.configs import LOCAL_BASIC_EXTRA_CONF # LOCAL_EXTENDED_EXTRA_CONF
16-
from brus_backend_common.models import LAKEHOUSE_MODELS, LAKEHOUSE_BUCKET_NAMES
16+
from brus_backend_common.models import LAKEHOUSE_MODELS
1717
from brus_backend_common.scripts.create_migrate_lakehouse_model import main as create_migrate
1818

1919
if TYPE_CHECKING:
@@ -208,7 +208,7 @@ def delta_lake_unittest_schema(spark: "SparkSession", hive_unittest_metastore_db
208208

209209
@pytest.fixture(scope="session")
210210
def setup_teardown_buckets_session() -> Generator[List[str], None, None]:
211-
buckets = LAKEHOUSE_BUCKET_NAMES + [CONFIG.PUBLIC_FILES_BUCKET, CONFIG.METRICS_BUCKET, CONFIG.DATA_SOURCES_BUCKET]
211+
buckets = [getattr(CONFIG, bucket) for bucket in CONFIG_BUCKETS]
212212
for bucket in buckets:
213213
s3_unittest_data_bucket_setup(bucket)
214214

0 commit comments

Comments
 (0)