Help with test is undefined error

The problem I’m having

I keep getting the following error when I try to run my custom dbt test:

19:38:44  Completed with 1 error, 0 partial successes, and 0 warnings:
19:38:44  
19:38:44    Compilation Error in test at_least_one_row_mymodelname_ (models/summary/schema.yml)
  'test_at_least_one_row' is undefined. This can happen when calling a macro that does not exist. Check for typos and/or install package dependencies with "dbt deps".

What I’ve already tried

I’ve tried changing the file name and test name.

schema.yml

models:
  - name: mymodelname
    tests:
      - at_least_one_row:
          severity: warn

##at_least_one_row.sql

{% test at_least_one_row(model) %}

	
	select 1
	from {{ model }}
	limit 10

{% endtest %}

Any thoughts on what might be going on here?
I’m using dbt-core 1.9 in case that makes a difference.

Hi jpowell, how are you executing this test?

Hi @marcelo - I’ve tried the following:

dbt test --select test_name:at_least_one_row
dbt test --select mymodelname

Ok, and where is the test located?

The test is located in

my_project/tests

Try moving it to tests/generic

"Generic tests are defined in SQL files. Those files can live in two places:

  • tests/generic/: that is, a special subfolder named generic within your test paths (tests/ by default)
  • macros/: Why? Generic tests work a lot like macros, and historically, this was the only place they could be defined. If your generic test depends on complex macro logic, you may find it more convenient to define the macros and the generic test in the same file."

Source: Writing custom generic data tests | dbt Developer Hub

Fantastic, this worked. Thank you!

1 Like

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