EqualExperts/dbt-unit-testing

Ephemeral model dependency failure

Mantas-Skackauskas opened this issue · 4 comments

Hello. I'm having a problem with creating unit tests for models that have ephemeral model dependencies. Every time I run a unit test, the compiler asks me to include the ephemeral model as a dependency:

To fix this issue, add the following hint to the top of themodel "<materialized table model name>":

-- depends_on {{ ref('ephemeral model') }}

Adding this results in a failure with a message:

Runtime Error in <model_name> (<path>)
   TABLE_NOT_FOUND line x:y Table 'awsdatacatalog.<schema name>.__dbt__cte__<ephemeral model> does not exist

As a result, I'm unable to create tests for any models that have a first level dependency to ephemeral models. Any suggestions? Thanks.

Hi @Mantas-Skackauskas , are you using dbt_unit_testing.ref in your tests or are you overriding the ref macro? Could you please me which database are you using and the version of the dbt_unit_testing?

A code sample might be helpful too 🙂

Thanks

Sure,

My model follows this template:

-- depends_on: {{ ref('ephemeral_model') }}
-- depends_on: {{ ref('incremental_table_model') }}

{{
  config(
    tags='unit-test',
  )
}}

{% call dbt_unit_testing.test('model', 'description') %}

   {% call dbt_unit_testing.mock_ref('ephemeral_model') %}
     select 'val1' as col1
   {% endcall %}

   {% call dbt_unit_testing.mock_ref('incremental_table_model') %}
     select 'val2' as col2
   {% endcall %}

   {% call dbt_unit_testing.mock_source('schema','table') %}
     select 'val3' as col3
   {% endcall %}
  
   {% call dbt_unit_testing.expect() %}
     select 'val1' as col1, 'val2' as col2, 'val3' as col3
   {% endcall %}

{% endcall %}

Tested with 0.3.0 and 0.3.3. Both fail with the same error.

Hi @Mantas-Skackauskas , sorry for the late response.
From your description, I think that you are using

select * from {{ ref('model_ephemeral') }}

in your model and you are not overriding the ref macro as explained here

Please confirm.

Thank you

Closing due to inactivity. Happy to re-open if the issue is still happening.