Selecting all nodes but only tests for modified relations #12147
|
I have a dbt project where creating the relations is fairly quick but running all tests is beginning to add significant time to my CI / CD pipeline. I'd like to streamline it by creating all relations but only running the tests on modified relations and their ancestors / descendants. I know I can achieve this by sequencing dbt commands like this: dbt seed
dbt run
dbt test --select "@state:modified" --state ...But I would really like to capture all of this in a single selector that I can pass to
I tried this: dbt ls --exclude "state:unmodified,resource_type:test" --state ...But this excludes all tests. I think this is because all tests are considered nodes as well and while their parent model may have changed, they have not changed themselves and so are excluded. |
Replies: 1 comment 1 reply
|
You can do it in one (add Why your So flip it around and select tests by graph position instead. |
You can do it in one
dbt build. The reason it works withbuildspecifically:runandtestthrow away everything that isn't their own resource type as the final step, butbuildkeeps all of them. So you can union two selectors, "all models" and "tests in the modified graph":(add
resource_type:seed resource_type:snapshotto the first group if you use them.)Why your
--exclude "state:unmodified,resource_type:test"nuked every test: comma is intersection, so that reads as "nodes that are unmodified AND a test." A data test on a modified model didn't change itself, so it'sstate:un…