Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TestHooksInSourceFreshnessDisabled flaky test #10308

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor Author

@MichelleArk MichelleArk Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root cause: this clean-up call was missing from test_hooks_do_run_for_source_freshness initially, meaning the global active_deprecations was preserved across tests, triggering deprecations erronously (and cluttering up the logs)


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)
Loading