Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark Tests That Generate SQL-Engine-Specific Snapshots #828

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions metricflow/test/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def test_list_entities(capsys: pytest.CaptureFixture, cli_runner: MetricFlowCliR
assert "host" in resp.output


@pytest.mark.sql_engine_snapshot
def test_saved_query( # noqa: D
request: FixtureRequest,
capsys: pytest.CaptureFixture,
Expand All @@ -179,6 +180,7 @@ def test_saved_query( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_saved_query_with_where( # noqa: D
request: FixtureRequest,
capsys: pytest.CaptureFixture,
Expand Down Expand Up @@ -211,6 +213,7 @@ def test_saved_query_with_where( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_saved_query_with_limit( # noqa: D
request: FixtureRequest,
capsys: pytest.CaptureFixture,
Expand Down
25 changes: 25 additions & 0 deletions metricflow/test/dataflow/builder/test_dataflow_plan_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
logger = logging.getLogger(__name__)


@pytest.mark.sql_engine_snapshot
def test_simple_plan( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -60,6 +61,7 @@ def test_simple_plan( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_primary_entity_dimension( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -92,6 +94,7 @@ def test_primary_entity_dimension( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_joined_plan( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -129,6 +132,7 @@ def test_joined_plan( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_order_by_plan( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -166,6 +170,7 @@ def test_order_by_plan( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_limit_rows_plan( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -194,6 +199,7 @@ def test_limit_rows_plan( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_multiple_metrics_plan( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -227,6 +233,7 @@ def test_multiple_metrics_plan( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_single_semantic_model_ratio_metrics_plan(
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -260,6 +267,7 @@ def test_single_semantic_model_ratio_metrics_plan(
)


@pytest.mark.sql_engine_snapshot
def test_multi_semantic_model_ratio_metrics_plan(
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -293,6 +301,7 @@ def test_multi_semantic_model_ratio_metrics_plan(
)


@pytest.mark.sql_engine_snapshot
def test_multihop_join_plan( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -328,6 +337,7 @@ def test_multihop_join_plan( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_where_constrained_plan( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -370,6 +380,7 @@ def test_where_constrained_plan( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_where_constrained_plan_time_dimension( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -412,6 +423,7 @@ def test_where_constrained_plan_time_dimension( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_where_constrained_with_common_linkable_plan( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -454,6 +466,7 @@ def test_where_constrained_with_common_linkable_plan( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_multihop_join_plan_ambiguous_dim( # noqa: D
mf_test_session_state: MetricFlowTestSessionState,
dataflow_plan_builder: DataflowPlanBuilder,
Expand All @@ -476,6 +489,7 @@ def test_multihop_join_plan_ambiguous_dim( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_cumulative_metric_with_window( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -504,6 +518,7 @@ def test_cumulative_metric_with_window( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_cumulative_metric_no_window_or_grain_with_metric_time( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -531,6 +546,7 @@ def test_cumulative_metric_no_window_or_grain_with_metric_time( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_cumulative_metric_no_window_or_grain_without_metric_time( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -558,6 +574,7 @@ def test_cumulative_metric_no_window_or_grain_without_metric_time( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_distinct_values_plan( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -605,6 +622,7 @@ def test_distinct_values_plan( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_distinct_values_plan_with_join( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -653,6 +671,7 @@ def test_distinct_values_plan_with_join( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_measure_constraint_plan(
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -681,6 +700,7 @@ def test_measure_constraint_plan(
)


@pytest.mark.sql_engine_snapshot
def test_measure_constraint_with_reused_measure_plan(
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -709,6 +729,7 @@ def test_measure_constraint_with_reused_measure_plan(
)


@pytest.mark.sql_engine_snapshot
def test_common_semantic_model( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -739,6 +760,7 @@ def test_common_semantic_model( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_derived_metric_offset_window( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -766,6 +788,7 @@ def test_derived_metric_offset_window( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_derived_metric_offset_to_grain( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -793,6 +816,7 @@ def test_derived_metric_offset_to_grain( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_derived_metric_offset_with_granularity( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand All @@ -819,6 +843,7 @@ def test_derived_metric_offset_with_granularity( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_derived_offset_cumulative_metric( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import pytest
from _pytest.fixtures import FixtureRequest

from metricflow.dag.id_generation import OPTIMIZED_DATAFLOW_PLAN_PREFIX, IdGeneratorRegistry
Expand Down Expand Up @@ -28,6 +29,7 @@ def make_dataflow_plan(node: BaseOutput) -> DataflowPlan: # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_read_sql_source_combination( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -56,6 +58,7 @@ def test_read_sql_source_combination( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_filter_combination( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging

import pytest
from _pytest.fixtures import FixtureRequest
from dbt_semantic_interfaces.implementations.filters.where_filter import PydanticWhereFilter
from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity
Expand Down Expand Up @@ -150,6 +151,7 @@ def check_optimization( # noqa: D
assert source_counter.count_source_nodes(optimized_dataflow_plan) == expected_num_sources_in_optimized


@pytest.mark.sql_engine_snapshot
def test_2_metrics_from_1_semantic_model( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand All @@ -175,6 +177,7 @@ def test_2_metrics_from_1_semantic_model( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_2_metrics_from_2_semantic_models( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand All @@ -194,6 +197,7 @@ def test_2_metrics_from_2_semantic_models( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_3_metrics_from_2_semantic_models( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand All @@ -217,6 +221,7 @@ def test_3_metrics_from_2_semantic_models( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_constrained_metric_not_combined( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -252,6 +257,7 @@ def test_constrained_metric_not_combined( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_derived_metric( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand All @@ -274,6 +280,7 @@ def test_derived_metric( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_nested_derived_metric( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand All @@ -297,6 +304,7 @@ def test_nested_derived_metric( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_derived_metric_with_non_derived_metric( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -328,6 +336,7 @@ def test_derived_metric_with_non_derived_metric( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_2_ratio_metrics_from_1_semantic_model( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down
6 changes: 4 additions & 2 deletions metricflow/test/dataset/test_convert_semantic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import logging

import pytest
from _pytest.fixtures import FixtureRequest
from dbt_semantic_interfaces.references import SemanticModelReference

from metricflow.protocols.sql_client import SqlClient
from metricflow.sql.render.sql_plan_renderer import SqlQueryPlanRenderer
from metricflow.test.fixtures.model_fixtures import ConsistentIdObjectRepository
from metricflow.test.fixtures.setup_fixtures import MetricFlowTestSessionState
from metricflow.test.snapshot_utils import assert_spec_set_snapshot_equal
Expand All @@ -15,6 +15,7 @@
logger = logging.getLogger(__name__)


@pytest.mark.sql_engine_snapshot
def test_convert_table_semantic_model_without_measures( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand All @@ -40,6 +41,7 @@ def test_convert_table_semantic_model_without_measures( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_convert_table_semantic_model_with_measures( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
Expand Down Expand Up @@ -72,11 +74,11 @@ def test_convert_table_semantic_model_with_measures( # noqa: D
)


@pytest.mark.sql_engine_snapshot
def test_convert_query_semantic_model( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
sql_client: SqlClient,
default_sql_plan_renderer: SqlQueryPlanRenderer,
consistent_id_object_repository: ConsistentIdObjectRepository,
) -> None:
bookings_data_set = consistent_id_object_repository.simple_model_data_sets["revenue"]
Expand Down
22 changes: 22 additions & 0 deletions metricflow/test/fixtures/setup_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ def pytest_addoption(parser: _pytest.config.argparsing.Parser) -> None:
)


# Name of the pytest marker for tests that generate SQL-engine specific snapshots.
SQL_ENGINE_SNAPSHOT_MARKER_NAME = "sql_engine_snapshot"


def pytest_configure(config: _pytest.config.Config) -> None:
"""Hook as specified by the pytest API for configuration."""
config.addinivalue_line(
name="markers",
line=f"{SQL_ENGINE_SNAPSHOT_MARKER_NAME}: mark tests as generating a snapshot specific to a SQL engine",
)


def check_sql_engine_snapshot_marker(request: FixtureRequest) -> None:
"""Raises an error if the given test request does not have the sql-engine-test marker set."""
mark_names = set(mark.name for mark in request.node.iter_markers(name=SQL_ENGINE_SNAPSHOT_MARKER_NAME))
if SQL_ENGINE_SNAPSHOT_MARKER_NAME not in mark_names:
raise ValueError(
f"This test needs to be marked with '{SQL_ENGINE_SNAPSHOT_MARKER_NAME}' to keep track of all tests that "
f"generate SQL-engine specific snapshots."
)


@pytest.fixture(scope="session")
def mf_test_session_state( # noqa: D
request: FixtureRequest,
Expand Down
Loading