From 0f478a0f528c9c826269046bb533f02d4be3316a Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Thu, 13 Jun 2024 11:05:00 -0400 Subject: [PATCH] deflake source freshness hooks test --- .../sources/test_source_freshness.py | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/tests/functional/sources/test_source_freshness.py b/tests/functional/sources/test_source_freshness.py index 565b93a81e6..2f42a3aaa56 100644 --- a/tests/functional/sources/test_source_freshness.py +++ b/tests/functional/sources/test_source_freshness.py @@ -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): @@ -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, @@ -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: @@ -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, ): @@ -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): @@ -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, ): @@ -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)