# dbt unit test where source table has the same name as the model

**URL:** <https://discourse.getdbt.com/t/dbt-unit-test-where-source-table-has-the-same-name-as-the-model/14487>\
**Category:** Help\
**Created:** [July 24, 2024, 8:58am UTC](https://discourse.getdbt.com/t/dbt-unit-test-where-source-table-has-the-same-name-as-the-model/14487 "2024-07-24T08:58:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivan.ujlaky](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/ivan.ujlaky/32/4275_2.png) [@ivan.ujlaky](https://discourse.getdbt.com/u/ivan.ujlaky)\
**Post date:** [July 24, 2024, 8:58am UTC](https://discourse.getdbt.com/t/dbt-unit-test-where-source-table-has-the-same-name-as-the-model/14487/1 "2024-07-24T08:58:15Z")

</div>

I’m trying to create a unit test (Running with dbt=1.8.3, Registered adapter: trino=1.8.1) for incremental load based on the documentation: [Unit tests | dbt Developer Hub](https://docs.getdbt.com/docs/build/unit-tests#unit-testing-incremental-models)

The issue I’m facing is that my input source (from the sources.yaml) is a table that has the same name as the model. In the compiled sql it only creates one cte for the source and the {{ this }}) input and the execution fails. Do you have any suggestions?

## table\_name.sql

```auto
SELECT *
    FROM {{ source('test', 'table_name') }} table_name

    {% if is_incremental() %}
    WHERE table_name.updated_at >= (SELECT updated_at FROM {{ this }})
    {% endif %}

```

## unit\_test.yaml

```auto
unit_tests:
    - name: table_name_incremental_mode
      model: table_name
      overrides:
          macros:
              # unit test this model in "incremental" mode
              is_incremental: true
      given:
          - input: this
              rows:
                  - { event_id: 1, event_time: 2020-01-01}
          - input: source('test', 'table_name')
              rows:
                  - { event_id: 1, event_time: 2020-01-01}
                  - { event_id: 2, event_time: 2020-01-02}

```

---

<div class="post-metadata">

**Author:** ![ivan.ujlaky](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/ivan.ujlaky/32/4275_2.png) [@ivan.ujlaky](https://discourse.getdbt.com/u/ivan.ujlaky)\
**Post date:** [July 25, 2024, 12:02pm UTC](https://discourse.getdbt.com/t/dbt-unit-test-where-source-table-has-the-same-name-as-the-model/14487/2 "2024-07-25T12:02:25Z")

</div>

Found the bud ticket fir this one:

> <https://github.com/dbt-labs/dbt-core/issues/10433>
>
> \### Is this a new bug in dbt-core?
> 
> \- \[X\] I believe this is a new bug in dbt-cor…e
> \- \[X\] I have searched the existing issues, and I could not find an existing issue for this bug
> 
> \### Current Behavior
> 
> One of my models had the same name as the source Snowflake table. They live in different schemas. \`dbt run\` works fine and generates all the data as expected. However, DBT unit tests fail because unit tests can not differentiate mocked source tables from these tables. Here is an example:
> \`\`\`yaml
> unit\_tests:
> - name: test\_model\_1
> description:
> model: MODEL\_1
> overrides:
> macros:
> is\_incremental: true
> 
> given:
> - input: this
> rows:
> - { column\_1: "1", column\_2: "2" }
> 
> - input: source('src', 'MODEL\_1')
> rows:
> - { column\_1: "1", column\_2: "3" }
> 
> expect:
> rows:
> - { column\_1: "1", column\_2: "3" }
> \`\`\`
> 
> When I checked the generated SQL query, I saw that it adds \`\_\_dbt\_\_cte\_\_\` prefixes to the CTE names and replaced raws for \`source('src', 'MODEL\_1')\` with values from \`this\`.
> 
> \### Expected Behavior
> 
> Fix unit tests to support identical model and source table names in different schemas.
> 
> \### Steps To Reproduce
> 
> 1. Create a model that relies on a table with the table's exact name
> 2. Create an incremental unit test and add data both for the source table and \`this\` (the model itself)
> 3. Run the unit test and see its outcome
> 
> \### Relevant log output
> 
> \_No response\_
> 
> \### Environment
> 
> \`\`\`markdown
> \- OS:
> \- Python:
> \- dbt:
> \`\`\`
> 
> 
> \### Which database adapter are you using with dbt?
> 
> snowflake
> 
> \### Additional Context
> 
> \_No response\_
