Skip to content

Commit e2e1d7a

Browse files
committed
chore: fix dbt test flakiness
1 parent d249340 commit e2e1d7a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

tests/dbt/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,19 @@ def dbt_dummy_postgres_config() -> PostgresConfig:
127127
port=5432,
128128
schema="schema",
129129
)
130+
131+
132+
@pytest.fixture(scope="function", autouse=True)
133+
def reset_dbt_globals():
134+
# This fixture is used to clear the memoized cache for _get_package_with_retries
135+
# in dbt.clients.registry. This is necessary because the cache is shared across
136+
# tests and can cause unexpected behavior if not cleared as some tests depend on
137+
# the deprecation warning that _get_package_with_retries fires
138+
yield
139+
from dbt.clients.registry import _get_cached
140+
from dbt_common.events.functions import reset_metadata_vars
141+
142+
# https://github.com/dbt-labs/dbt-core/blob/main/core/dbt/tests/util.py#L82
143+
reset_metadata_vars()
144+
# https://github.com/dbt-labs/dbt-core/blob/main/tests/functional/conftest.py#L9
145+
_get_cached.cache = {}

tests/dbt/test_model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from sqlglot import exp
77
from sqlglot.errors import SchemaError
88
from sqlmesh import Context
9+
from sqlmesh.core.console import NoopConsole, get_console
910
from sqlmesh.core.model import TimeColumn, IncrementalByTimeRangeKind
1011
from sqlmesh.core.model.kind import OnDestructiveChange, OnAdditiveChange
1112
from sqlmesh.core.state_sync.db.snapshot import _snapshot_to_json
@@ -537,6 +538,7 @@ def test_load_deprecated_incremental_time_column(
537538
f.write(incremental_time_range_contents)
538539

539540
snapshot_fqn = '"local"."main"."incremental_time_range"'
541+
assert isinstance(get_console(), NoopConsole)
540542
context = Context(paths=project_dir)
541543
model = context.snapshots[snapshot_fqn].model
542544
# Validate model-level attributes

0 commit comments

Comments
 (0)