Custom test isn't being inserted into dbt_internal_test subquery

The issue I am having is, whenever I build my custom tests, I get an error. After inspecting the target code, it looks like the FROM is never being populated.

I even tried using code from the documentation and that fails to build as well. I am curious if this is a bug or if am I missing something obvious.

Here is the test code:

{% test Currency(model, column_name) %}

    SELECT *
    FROM {{ model }}
    WHERE NOT REGEXP_LIKE({{ column_name }}, '^[0-9]+(\.[0-9]{1,2})?$')

{% endtest %}

All it does is figure out if the value is a valid currency.

The compiled code looks like this:

select
      count(*) as failures,
      count(*) != 0 as should_warn,
      count(*) != 0 as should_error
    from (
      
      
    ) dbt_internal_test
The error message is:
Database Error in test Currency (tests\Currency.sql)
 001003 (42000): SQL compilation error:
syntax error line 8 at position 4 unexpected ')'.
compiled Code at target\run\ea_data_analytics\tests\Currency.sql

Makes sense why it fails, but, why does it refuse to replace the {{model}} . Also, where has my logic gone? It makes sense that it should appear in the FROM as an embedded query but does not. Is this a bug? Or did I miss something.

Can you post the YAML where you’re attaching the test to a model?

sure:


version: 2 
      
sources:
  - name: test_staging
    database: <database>(exists but did not want to share it)
    schema: common
    tables:
      - name: test_test

OK, it doesn’t look like the test is actually linked to your source. It should look something like this:

version: 2 
      
sources:
  - name: test_staging
    database: <database>
    schema: common
    tables:
      - name: test_test
        columns: 
          - name: currency_col
            tests:
              - Currency

Check out the docs on tests for more examples: Tests | dbt Developer Hub