unable to infer dependencies for custom tests

I’m having the exact problem described at 0.19.1 unable to infer dependencies for custom tests · Issue #3229 · dbt-labs/dbt-core · GitHub, though I’m using this form instead:

(% test ... %}
{% endtest %}

To summarize, I’m trying to have a generic test depend on a model other than the one being tested.

The workaround listed above does work, but adds an unfortunate verbosity to every use of the test.

I have tried adding the -- depends_on: {{ ref('model_b') }} (with my ‘model_b’) at various places in the test file, to no avail.

The GitHub issue claims it was fixed a long time ago; I’m on 1.5.9. Did that issue only get fixed for macros, and not generic tests?

-- {{ ref('model_b') }}
can you try like this

1 Like

That does work!

I made a reduced and redacted version that could be used for testing; adding or removing the comment determines whether the error appears.

Oh, and I forgot to mention I’m using snowflake plugin, 1.5.1.

{% test valid_widgets(model, column_name, row_condition, allow_gizmo = True) %}
-- {{ ref('widgets') }}
-- remove the above comment to see the error
    with widgets_filtered as (

        select widget
        from {{ ref('widgets') }}
        {%- if not allow_gizmo %}
        where widget <> 'gizmo'
        {% endif %}

    )

    select {{ column_name }}
    from {{ model }}
    where
        {{ column_name }} is not null
    and
        {{ column_name }} not in (select widget from widgets_filtered)
    {%- if row_condition %}
    and
        {{ row_condition }}
    {% endif %}

{% endtest %}

The reference does not appear like it’s in a conditional position, right?