Skip to content

Commit ea4e368

Browse files
committed
Configure tests from dbt_project.yml
1 parent f021399 commit ea4e368

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

core/dbt/config/project.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,14 @@ def create_project(self, rendered: RenderComponents) -> 'Project':
353353
seeds: Dict[str, Any]
354354
snapshots: Dict[str, Any]
355355
sources: Dict[str, Any]
356+
tests: Dict[str, Any]
356357
vars_value: VarProvider
357358

358359
models = cfg.models
359360
seeds = cfg.seeds
360361
snapshots = cfg.snapshots
361362
sources = cfg.sources
363+
tests = cfg.tests
362364
if cfg.vars is None:
363365
vars_dict: Dict[str, Any] = {}
364366
else:
@@ -408,6 +410,7 @@ def create_project(self, rendered: RenderComponents) -> 'Project':
408410
selectors=selectors,
409411
query_comment=query_comment,
410412
sources=sources,
413+
tests=tests,
411414
vars=vars_value,
412415
config_version=cfg.config_version,
413416
unrendered=unrendered,
@@ -513,6 +516,7 @@ class Project:
513516
seeds: Dict[str, Any]
514517
snapshots: Dict[str, Any]
515518
sources: Dict[str, Any]
519+
tests: Dict[str, Any]
516520
vars: VarProvider
517521
dbt_version: List[VersionSpecifier]
518522
packages: Dict[str, Any]
@@ -571,6 +575,7 @@ def to_project_config(self, with_packages=False):
571575
'seeds': self.seeds,
572576
'snapshots': self.snapshots,
573577
'sources': self.sources,
578+
'tests': self.tests,
574579
'vars': self.vars.to_dict(),
575580
'require-dbt-version': [
576581
v.to_version_string() for v in self.dbt_version

core/dbt/config/renderer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def should_render_keypath(self, keypath: Keypath) -> bool:
145145
if first == 'vars':
146146
return False
147147

148-
if first in {'seeds', 'models', 'snapshots', 'seeds'}:
148+
if first in {'seeds', 'models', 'snapshots', 'tests'}:
149149
keypath_parts = {
150150
(k.lstrip('+') if isinstance(k, str) else k)
151151
for k in keypath

core/dbt/config/runtime.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def from_parts(
110110
selectors=project.selectors,
111111
query_comment=project.query_comment,
112112
sources=project.sources,
113+
tests=project.tests,
113114
vars=project.vars,
114115
config_version=project.config_version,
115116
unrendered=project.unrendered,
@@ -272,7 +273,7 @@ def _get_config_paths(
272273
return frozenset(paths)
273274

274275
def get_resource_config_paths(self) -> Dict[str, PathSet]:
275-
"""Return a dictionary with 'seeds' and 'models' keys whose values are
276+
"""Return a dictionary with resource type keys whose values are
276277
lists of lists of strings, where each inner list of strings represents
277278
a configured path in the resource.
278279
"""
@@ -281,6 +282,7 @@ def get_resource_config_paths(self) -> Dict[str, PathSet]:
281282
'seeds': self._get_config_paths(self.seeds),
282283
'snapshots': self._get_config_paths(self.snapshots),
283284
'sources': self._get_config_paths(self.sources),
285+
'tests': self._get_config_paths(self.tests),
284286
}
285287

286288
def get_unused_resource_config_paths(
@@ -488,6 +490,7 @@ def from_parts(
488490
selectors=project.selectors,
489491
query_comment=project.query_comment,
490492
sources=project.sources,
493+
tests=project.tests,
491494
vars=project.vars,
492495
config_version=project.config_version,
493496
unrendered=project.unrendered,

core/dbt/context/context_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def get_config_dict(self, resource_type: NodeType) -> Dict[str, Any]:
4141
model_configs = unrendered.get('snapshots')
4242
elif resource_type == NodeType.Source:
4343
model_configs = unrendered.get('sources')
44+
elif resource_type == NodeType.Test:
45+
model_configs = unrendered.get('tests')
4446
else:
4547
model_configs = unrendered.get('models')
4648

@@ -61,6 +63,8 @@ def get_config_dict(self, resource_type: NodeType) -> Dict[str, Any]:
6163
model_configs = self.project.snapshots
6264
elif resource_type == NodeType.Source:
6365
model_configs = self.project.sources
66+
elif resource_type == NodeType.Test:
67+
model_configs = self.project.tests
6468
else:
6569
model_configs = self.project.models
6670
return model_configs

core/dbt/contracts/project.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class Project(HyphenatedDbtClassMixin, Replaceable):
195195
snapshots: Dict[str, Any] = field(default_factory=dict)
196196
analyses: Dict[str, Any] = field(default_factory=dict)
197197
sources: Dict[str, Any] = field(default_factory=dict)
198+
tests: Dict[str, Any] = field(default_factory=dict)
198199
vars: Optional[Dict[str, Any]] = field(
199200
default=None,
200201
metadata=dict(

0 commit comments

Comments
 (0)