Skip to content

Commit 3ea6edb

Browse files
Add regression tests for limit handling in test SQL generation (#638).
Covers sqlserver__get_test_sql's `top (...)` conditional both with and without an explicit `limit` config on a generic test. The macro currently guards correctly (`if limit != none`); these tests trip if that guard is ever removed or broken — without them, a regression that produced `select top () failures …` would only surface against models where tests actually run. No production change.
1 parent 4b295d9 commit 3ea6edb

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import pytest
2+
3+
from dbt.tests.util import run_dbt
4+
5+
seed_csv = """id,name
6+
1,alice
7+
2,bob
8+
3,charlie
9+
"""
10+
11+
schema_yml = """
12+
version: 2
13+
seeds:
14+
- name: test_seed
15+
columns:
16+
- name: id
17+
tests:
18+
- unique
19+
- not_null
20+
"""
21+
22+
schema_with_limit_yml = """
23+
version: 2
24+
seeds:
25+
- name: test_seed
26+
columns:
27+
- name: id
28+
tests:
29+
- unique:
30+
config:
31+
limit: 10
32+
- not_null:
33+
config:
34+
limit: 10
35+
"""
36+
37+
38+
class TestLimitNone:
39+
@pytest.fixture(scope="class")
40+
def seeds(self):
41+
return {"test_seed.csv": seed_csv}
42+
43+
@pytest.fixture(scope="class")
44+
def models(self):
45+
return {"schema.yml": schema_yml}
46+
47+
def test_unique_test_on_seed(self, project):
48+
run_dbt(["seed"])
49+
results = run_dbt(["test"])
50+
assert len(results) == 2
51+
for result in results:
52+
assert result.status == "pass"
53+
54+
55+
class TestLimitExplicit:
56+
@pytest.fixture(scope="class")
57+
def seeds(self):
58+
return {"test_seed.csv": seed_csv}
59+
60+
@pytest.fixture(scope="class")
61+
def models(self):
62+
return {"schema.yml": schema_with_limit_yml}
63+
64+
def test_unique_test_with_limit(self, project):
65+
run_dbt(["seed"])
66+
results = run_dbt(["test"])
67+
assert len(results) == 2
68+
for result in results:
69+
assert result.status == "pass"

0 commit comments

Comments
 (0)