Skip to content

Commit

Permalink
Share patch_id_generators between metricflow/`metricflow-semantic…
Browse files Browse the repository at this point in the history
…s` (#1468)

`patch_id_generators` is a fixture that is duplicated between
`metricflow` and `metricflow-semantics`, so this PR consolidates them to
a common file.
  • Loading branch information
plypaul authored Oct 21, 2024
1 parent b1296d9 commit e28c3e6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from typing import Generator
from unittest.mock import patch

import pytest

from metricflow_semantics.dag.sequential_id import SequentialIdGenerator


Expand All @@ -28,6 +30,17 @@ def patch_id_generators_helper(start_value: int) -> Generator[None, None, None]:
yield None


@pytest.fixture(autouse=True, scope="function")
def patch_id_generators() -> Generator[None, None, None]:
"""Patch ID generators with a new one to get repeatability in plan outputs before every test.
Plan outputs contain IDs, so if the IDs are not consistent from run to run, there will be diffs in the actual vs.
expected outputs during a test.
"""
with patch_id_generators_helper(start_value=IdNumberSpace.for_test_start().start_value):
yield None


@dataclass(frozen=True)
class IdNumberSpace:
"""Defines the numbering of IDs when setting up tests and test fixtures."""
Expand Down
3 changes: 2 additions & 1 deletion metricflow-semantics/tests_metricflow_semantics/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# These imports are required to properly set up pytest fixtures.
from __future__ import annotations

from tests_metricflow_semantics.fixtures.id_fixtures import * # noqa: F401, F403
from metricflow_semantics.test_helpers.id_helpers import patch_id_generators # noqa: F401

from tests_metricflow_semantics.fixtures.manifest_fixtures import * # noqa: F401, F403
from tests_metricflow_semantics.fixtures.setup_fixtures import * # noqa: F401, F403

This file was deleted.

3 changes: 2 additions & 1 deletion tests_metricflow/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# These imports are required to properly set up pytest fixtures.
from __future__ import annotations

from metricflow_semantics.test_helpers.id_helpers import patch_id_generators # noqa: F401

from tests_metricflow.fixtures.cli_fixtures import * # noqa: F401, F403
from tests_metricflow.fixtures.dataflow_fixtures import * # noqa: F401, F403
from tests_metricflow.fixtures.id_fixtures import * # noqa: F401, F403
from tests_metricflow.fixtures.manifest_fixtures import * # noqa: F401, F403
from tests_metricflow.fixtures.setup_fixtures import * # noqa: F401, F403
from tests_metricflow.fixtures.sql_client_fixtures import * # noqa: F401, F403
Expand Down
17 changes: 0 additions & 17 deletions tests_metricflow/fixtures/id_fixtures.py

This file was deleted.

0 comments on commit e28c3e6

Please sign in to comment.