Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] UnitTests: Mocking the run_query macro to retrieve data from a given Mocked Source/Reference #11126

Open
megetron3 opened this issue Dec 11, 2024 · 0 comments
Labels
enhancement New feature or request triage

Comments

@megetron3
Copy link

megetron3 commented Dec 11, 2024

The macros/models are executing the run_query function, but instead of querying the database, I would like run_query to query the mocked source defined in the unit tests.
Instead of doing this in the test:

overrides:
  macros:
    run_query:
      rows:
        - { id: 1 }

I want to mock the data directly in the ref model, such as ref('model_a'), and use it with run_query.
Example Model Code:

-- model_b.sql
run_query("select * from {{ ref('model_a') }}")

OR

-- models/model_b.sql
select * from database.schema.model_a_table
where id is not null

Example Unit Test:

unit_tests:
  - name: my_unit_test
    model: model_b
    given:
      - input: ref('model_a')
        rows:
          - {id: 1}
    expect:
      rows:
        - {id: 1}

By defining the test inputs directly in the ref model, we avoid the need to override run_query using macros, providing a clearer and more maintainable testing strategy.

@megetron3 megetron3 added enhancement New feature or request triage labels Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage
Projects
None yet
Development

No branches or pull requests

1 participant