Skip to content

Commit 1540e8b

Browse files
committed
group overrides from dbt 1.9.4 and above
1 parent 18d1a7c commit 1540e8b

1 file changed

Lines changed: 7 additions & 27 deletions

File tree

integration_tests/tests/test_dbt_artifacts/test_groups.py

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
Covers models, tests, seeds, and snapshots group assignment and artifact table correctness.
44
"""
55
import contextlib
6-
import subprocess
76
import uuid
87

98
import pytest
@@ -46,26 +45,6 @@ def _normalize_empty(val):
4645
return val if val not in (None, "") else None
4746

4847

49-
def print_dbt_log_tail(n=40):
50-
try:
51-
output = subprocess.check_output(["tail", f"-n{n}", "logs/dbt.log"], text=True)
52-
print("\n--- dbt log tail ---\n", output)
53-
except Exception as e:
54-
print(f"Could not read dbt log: {e}")
55-
56-
57-
def run_dbt_and_check(cmd, *args, **kwargs):
58-
result = cmd(*args, **kwargs)
59-
print_dbt_log_tail() # Always print log tail
60-
# If result is a dict or object, check for success
61-
if hasattr(result, "success") and not result.success:
62-
assert False, f"dbt command failed: {result}"
63-
elif isinstance(result, dict) and not result.get("success", True):
64-
assert False, f"dbt command failed: {result}"
65-
# If result is None, rely on downstream assertions
66-
return result
67-
68-
6948
@pytest.mark.parametrize(
7049
"group_config, expected_groups, test_name",
7150
[
@@ -161,7 +140,7 @@ def test_dbt_groups_artifact_parametrized(
161140
name=f"groups_test_{test_name}_{unique_id}.yml",
162141
):
163142
dbt_project.dbt_runner.vars["disable_dbt_artifacts_autoupload"] = False
164-
run_dbt_and_check(dbt_project.dbt_runner.run)
143+
dbt_project.dbt_runner.run()
165144
dbt_project.assert_table_exists("dbt_groups")
166145
for group_name, owner_name, owner_email in patched_expected_groups:
167146
group = _get_group_from_table(dbt_project, group_name)
@@ -220,7 +199,7 @@ def test_model_group_attribute(dbt_project: DbtProject, tmp_path):
220199
dbt_model_path.write_text(model_sql)
221200
try:
222201
dbt_project.dbt_runner.vars["disable_dbt_artifacts_autoupload"] = False
223-
run_dbt_and_check(dbt_project.dbt_runner.run, select=model_name)
202+
dbt_project.dbt_runner.run(select=model_name)
224203
dbt_project.assert_table_exists("dbt_models")
225204
models = dbt_project.read_table(
226205
"dbt_models", where=f"name = '{model_name}'", raise_if_empty=True
@@ -280,7 +259,7 @@ def test_test_group_attribute(dbt_project: DbtProject, tmp_path):
280259
dbt_model_path.write_text(model_sql)
281260
try:
282261
dbt_project.dbt_runner.vars["disable_dbt_artifacts_autoupload"] = False
283-
run_dbt_and_check(dbt_project.dbt_runner.run, select=model_name)
262+
dbt_project.dbt_runner.run(select=model_name)
284263
dbt_project.assert_table_exists("dbt_tests")
285264
tests = dbt_project.read_table(
286265
"dbt_tests", where="name LIKE 'unique%'", raise_if_empty=True
@@ -295,6 +274,7 @@ def test_test_group_attribute(dbt_project: DbtProject, tmp_path):
295274
dbt_model_path.unlink()
296275

297276

277+
@pytest.mark.requires_dbt_version("1.9.4")
298278
def test_test_override_group(dbt_project: DbtProject, tmp_path):
299279
"""
300280
Test that a singular test defined in schema.yml, which belongs to a model with a group, but also has a config: section with another group,
@@ -344,7 +324,7 @@ def test_test_override_group(dbt_project: DbtProject, tmp_path):
344324
dbt_model_path.write_text(model_sql)
345325
try:
346326
dbt_project.dbt_runner.vars["disable_dbt_artifacts_autoupload"] = False
347-
run_dbt_and_check(dbt_project.dbt_runner.run, select=model_name)
327+
dbt_project.dbt_runner.run(select=model_name)
348328
dbt_project.assert_table_exists("dbt_tests")
349329
tests = dbt_project.read_table(
350330
"dbt_tests", where="name LIKE 'unique%'", raise_if_empty=True
@@ -411,7 +391,7 @@ def test_seed_group_attribute(dbt_project: DbtProject, tmp_path):
411391
dbt_seed_path.write_text(seed_csv)
412392
# Run dbt seed
413393
dbt_project.dbt_runner.vars["disable_dbt_artifacts_autoupload"] = False
414-
run_dbt_and_check(dbt_project.dbt_runner.seed, select=seed_name)
394+
dbt_project.dbt_runner.seed(select=seed_name)
415395
dbt_project.assert_table_exists("dbt_seeds")
416396
seeds = dbt_project.read_table(
417397
"dbt_seeds", where=f"name = '{seed_name}'", raise_if_empty=True
@@ -481,7 +461,7 @@ def test_snapshot_group_attribute(dbt_project: DbtProject, tmp_path):
481461
dbt_snapshot_path.write_text(snapshot_sql)
482462
# Run dbt snapshot (runs all snapshots, as selecting is not supported by the runner)
483463
dbt_project.dbt_runner.vars["disable_dbt_artifacts_autoupload"] = False
484-
run_dbt_and_check(dbt_project.dbt_runner.run)
464+
dbt_project.dbt_runner.run()
485465
dbt_project.assert_table_exists("dbt_snapshots")
486466
snapshots = dbt_project.read_table(
487467
"dbt_snapshots", where=f"name = '{snapshot_name}'", raise_if_empty=False

0 commit comments

Comments
 (0)