Selector not finding nodes for `dbt test`

14.9k Views Asked by At

I'm trying to define a dbt YAML selector so that I can run schema tests for a particular set of models.

The YAML selector looks sort of like this:

selectors:
  - name: test_selector
    definition:
      union:
        - intersection:
            - node+
            - tag:tag1
        - intersection:
            - node+
            - tag:tag2
        - intersection:
            - node+
            - +tag:tag3
        - intersection:
            - node+
            - +tag:tag4
        - exclude:
            - config.materialized:view
            - config.materialized:materialized_view

This selector describes a selection of nodes upstream from a single node and downstream of a union of nodes, excluding views and materialized views (custom in our dbt project).

Using this syntax, I can successfully list the nodes specified by this syntax using dbt ls --selector test_selector --output name and successfully run the specified models using dbt run --selector test_selector, but the same behaviour does not seem to work for dbt test.

When I try dbt test --selector test_selector, I receive the output

WARNING: Nothing to do. Try checking your model configs and model specification args

I would expect that similar to dbt test, this command would run all of the tests associated with the models specified in the test_selector selection, but this does not appear to be the case.

It seems that the --selector flag is specified for dbt test in the syntax overview, and the Test Selection examples portion of the docs mentions "you can use selector methods that check config properties of the resources being tested". There aren't any examples of using the --selector flag with tests so I'm not sure if I'm missing something. Should this type of syntax be supported or am I misunderstanding the docs? Thanks!

1

There are 1 best solutions below

1
On

So glad you're making use of YAML selectors!

There is a known bug when using tests + the config.materialized:view selector in combination: https://github.com/fishtown-analytics/dbt/issues/2806. It's 100% limited to the "view" materialization. Given your selector definition, which excludes all config.materialized:view, the current behavior is to erroneously exclude all tests. There's nothing you're doing wrong; we're working to resolve that issue for the next version of dbt.

In the meantime, if you can specify that logic differently—e.g. instead of excluding all view-materialized models, excluding all models in the staging directory—I'd recommend giving it a go.