-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add model_sql helper to enable isolated unit testing #3476
Conversation
Thanks for your pull request, and welcome to our community! We require contributors to sign our Contributor License Agreement and we don't seem to have your signature on file. Check out this article for more information on why we have a CLA. In order for us to review and merge your code, please submit the Individual Contributor License Agreement form attached above above. If you have questions about the CLA, or if you believe you've received this message in error, don't hesitate to ping @drewbanin. CLA has not been signed by users: @Zatte |
@drewbanin I did sign the CLA some time ago but the PR seems stuck in this state. Anything you can help with? |
@cla-bot check |
The cla-bot has been summoned, and re-checked this pull request! |
@Zatte Apologies, the delay here is completely on me. I'm playing catch-up this week; I'm going to do my best to take a detailed look and give you feedback soon. |
@jtcohen6 : Just a monthly ping, hoping this is not forgotten until the end of times :) |
This PR has been marked as Stale because it has been open for 180 days with no activity. If you would like the PR to remain open, please remove the stale label or comment on the PR, or it will be closed in 7 days. |
Improves Unit testing capabilities.
Enabler for: #2354
Discussed here: https://discourse.getdbt.com/t/testing-with-fixed-data-set/564/8
Related: https://discourse.getdbt.com/t/state-of-testing-in-dbt/1778
Description
It didn't seem to be a good(relatively speaking) method for testing models in isolation. The best was introducing branching conditions in the model based on global settings which at most allowed for 1 test / model.
This PR introduces a new helper-method
model_sql()
(the name is debatable, in previous discussions it was calledcte
) which returns the compiled SQL code of a model but under a different context (allows one to overridesvar
/ref
/source
). Models can be tested without changes outside test code and multiple tests can be build for the same model.I think think approach is a cleaner approach to (unit) testing than what has been proposed so far.
Example use case:
Model
models/addder.sql
Test
tests/adder_0001.sql
_I haven't been writing python for some 6 years and and this is the first time interacting the the DBT core, as such the PR is not yet complete. I would like to get some feedback before investing more time into this. No point in "polishing a turd".
If the maintainer(s) think it holds value i don't mind ticking all the boxes below (or hand it over to someone else)_
Checklist
CHANGELOG.md
and added information about my change to the "dbt next" section.