Unit_Test depends on a node named with version '2' which was not found

The problem I’m having

dbt Unit Test is not able to find the version 2 of my model.

Let’s take an example of a model I’m trying to test.

with

source as (

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

)

, model_with_version as (

    select
        col1
        , col2

    from {{ ref('model_with_version', v=2) }}

)

select * from source

(This is an example, I know model_with_version is not selected in any way in this query)

With this unit test

unit_tests:
  - name: filter_test
    model: my_model_name
    overrides:
      macros:
        is_incremental: false
    given:
      - input: ref('model_with_version')
        rows:
          - {col1: test, col2: test2}
          - {col1: test2, col2: test2}
    expect:
      rows:
          - {col1: test, col2: test2}

If I run the command dbt test --select "my_model_name,test_type:unit" dbt will return

  Unit_Test 'filter_test` depends on a node named `model_with_version` with version '2' which was not found.

I’ve make sure the version 2 exist.
I can easily run dbt run -m model_with_version.v2 and it run successfully.

Note that the latest version is currently version 1, in my YAML file.

I’ve also tried to add the pin version to the ref in the unit test yml file.
Like this - input: ref('model_with_version', v=2)
But ended up with this error.

  An error occurred during execution of unit test 'filter_test'. There may be an error in the unit test definition: check the data types.
   Database Error
    002003 (42S02): SQL compilation error:
    Object '__DBT__CTE__MODEL_WITH_VERSION_V2' does not exist or not authorized.

The context of why I’m trying to do this

I’m trying to configure a unit test for a model that uses dbt version.

What I’ve already tried

  1. Configuring the models version in the input.
  2. Trying without version

Some example code or error messages

  Unit_Test 'filter_test` depends on a node named `model_with_version` with version '2' which was not found.
  An error occurred during execution of unit test 'filter_test'. There may be an error in the unit test definition: check the data types.
   Database Error
    002003 (42S02): SQL compilation error:
    Object '__DBT__CTE__MODEL_WITH_VERSION_V2' does not exist or not authorized.

More Informations

If I configure the input as - input: ref('model_with_version') then in the query I can see that the query generate the static inputs

__dbt__cte__model_with_version

but my code want to select from

    select
        address
        , validator_commission_rate

    from __dbt__cte__model_with_version_v2

Which fails.