issue with dbt test not being recognized

I am persistently getting an undefined error for my generic test:

I have written a generic test in dbt: is_postive.sql

{% test is_postive(model, column_name) %}

select 
    {{ column_name }}
from {{ model }} 
where {{ column_name }} < 0

{% endtest %}

This test is located in the tests/generic folder in my dbt project. The dbt project yaml file sets the tests location to this folder test-paths: ["tests"]

I am trying to reference this test in a yaml file for a model:

models:
  - name: fct__monthly_revenue
    tests:
      - unique:
          column_name: "id || '-' || date"
    config:
      schema: analytics
    columns: 
      - name: revenue
        tests:
          - is_positive:
              severity: warn

however, when I try to build the model I get this error:

Compilation Error in test is_positive_fct__monthly_revenue_revenue (models/analytics/fpaa/fpaa_revenue.yml)
  'test_is_positive' is undefined. This can happen when calling a macro that does not exist. Check for typos and/or install package dependencies with "dbt deps".

Some things I have tried already:

  • changing the file name to test_is_positive.sql
  • originally had the test directly in the test folder instead of the generic sub-folder
  • putting config in my yaml file a la:
    columns: 
      - name: revenue
        tests:
          - is_positive:
              config:
                severity: warn

I could use the accepted range from dbt_utils but I’d like to build more custom generic tests and so I’m trying to get a relatively simple one to work first

hm. your test name is is_postive
the thing you’re trying to call in your yml is is_positive:

tests:
     - is_positive:
           severity: warn

oh my god :woman_facepalming:, thank you!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.