Skip to content

Commit

Permalink
Merge pull request #721 from dbt-labs/improve-test-convenience
Browse files Browse the repository at this point in the history
Make test execution more consistent and convenient
  • Loading branch information
tlento authored Aug 16, 2023
2 parents b052a8c + 76d4aeb commit d41776b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20230814-225729.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Make duckdb the standard for all dev-env environment runs, including `make test`
time: 2023-08-14T22:57:29.775028-07:00
custom:
Author: tlento
Issue: "723"
1 change: 1 addition & 0 deletions .github/workflows/cd-sql-engine-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: MetricFlow SQL Engine Tests
# slower. As the test will be I/O bound, the tests can be run with higher parallelism to get faster runtimes.

on:
workflow_dispatch:
push:
branches:
- main
Expand Down
19 changes: 7 additions & 12 deletions metricflow/test/fixtures/setup_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import datetime
import logging
import os
import warnings
from dataclasses import dataclass

Expand Down Expand Up @@ -68,24 +69,18 @@ def pytest_addoption(parser: _pytest.config.argparsing.Parser) -> None:
)


class MetricFlowTestEnvironmentVariables:
"""Environment variables to setup the testing environment."""

MF_SQL_ENGINE_URL = EnvironmentVariable("MF_SQL_ENGINE_URL")
MF_SQL_ENGINE_PASSWORD = EnvironmentVariable("MF_SQL_ENGINE_PASSWORD")


@pytest.fixture(scope="session")
def mf_test_session_state( # noqa: D
request: FixtureRequest,
disable_sql_alchemy_deprecation_warning: None,
source_table_snapshot_repository: SqlTableSnapshotRepository,
) -> MetricFlowTestSessionState:
engine_url = MetricFlowTestEnvironmentVariables.MF_SQL_ENGINE_URL.get_optional()
if engine_url is None:
logger.info(f"{MetricFlowTestEnvironmentVariables.MF_SQL_ENGINE_URL.name} has not been set, so using DuckDb")
engine_url = "duckdb://"
engine_password = MetricFlowTestEnvironmentVariables.MF_SQL_ENGINE_PASSWORD.get_optional() or ""
engine_url = os.environ.get("MF_SQL_ENGINE_URL")
assert engine_url is not None, (
"MF_SQL_ENGINE_URL environment variable has not been set! Are you running in a properly configured "
"environment? Check out our CONTRIBUTING.md for pointers to our environment configurations."
)
engine_password = os.environ.get("MF_SQL_ENGINE_PASSWORD", "")

current_time = datetime.datetime.now().strftime("%Y_%m_%d")
random_suffix = random_id()
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ features = [

[tool.hatch.envs.dev-env.env-vars]
MF_TEST_ADAPTER_TYPE="duckdb"
MF_SQL_ENGINE_URL="duckdb://"

[tool.hatch.envs.postgres-env.env-vars]
MF_SQL_ENGINE_URL="postgresql://metricflow@localhost:5432/metricflow"
Expand Down

0 comments on commit d41776b

Please sign in to comment.