Skip to content

Commit 1ee0db5

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

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-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 = {}

0 commit comments

Comments
 (0)