Skip to content

Commit

Permalink
deflake source freshness hooks test
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Jun 13, 2024
1 parent 8639290 commit 0f478a0
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions tests/functional/sources/test_source_freshness.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ def _assert_freshness_results(self, path, state):
}
]

def _assert_project_hooks_called(self, logs: str):
assert "Running 1 on-run-start hook" in logs
assert "Running 1 on-run-end hook" in logs

def _assert_project_hooks_not_called(self, logs: str):
assert "Running 1 on-run-start hook" not in logs
assert "Running 1 on-run-end hook" not in logs


class TestSourceFreshness(SuccessfulSourceFreshnessTest):
def test_source_freshness(self, project):
Expand Down Expand Up @@ -428,11 +436,17 @@ def project_config_update(self):
},
}

@pytest.fixture(scope="class")
def global_deprecations(self):
deprecations.reset_deprecations()
yield
deprecations.reset_deprecations()

def test_hooks_do_run_for_source_freshness(
self,
project,
global_deprecations,
):
deprecations.reset_deprecations()
assert deprecations.active_deprecations == set()
_, log_output = self.run_dbt_and_capture_with_vars(
project,
Expand Down Expand Up @@ -472,8 +486,8 @@ def test_hooks_do_run_for_source_freshness(
],
expect_pass=False,
)
assert "on-run-start" in log_output
assert "on-run-end" in log_output

self._assert_project_hooks_called(log_output)


class TestHooksInSourceFreshnessError:
Expand Down Expand Up @@ -526,7 +540,7 @@ def project_config_update(self):
},
}

def test_hooks_do_run_for_source_freshness(
def test_hooks_do_not_run_for_source_freshness(
self,
project,
):
Expand All @@ -538,8 +552,7 @@ def test_hooks_do_run_for_source_freshness(
],
expect_pass=False,
)
assert "on-run-start" not in log_output
assert "on-run-end" not in log_output
self._assert_project_hooks_not_called(log_output)


class TestHooksInSourceFreshnessDefault(SuccessfulSourceFreshnessTest):
Expand All @@ -551,7 +564,7 @@ def project_config_update(self):
"on-run-end": ["{{ log('on-run-end hooks called') }}"],
}

def test_hooks_do_run_for_source_freshness(
def test_hooks_do_not_run_for_source_freshness(
self,
project,
):
Expand All @@ -564,5 +577,4 @@ def test_hooks_do_run_for_source_freshness(
expect_pass=False,
)
# default behaviour - no hooks run in source freshness
assert "on-run-start" not in log_output
assert "on-run-end" not in log_output
self._assert_project_hooks_not_called(log_output)

0 comments on commit 0f478a0

Please sign in to comment.