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

Add support for inline (non-materialized) unit tests #2

Closed
mjirv opened this issue Jul 14, 2021 · 0 comments · Fixed by #3
Closed

Add support for inline (non-materialized) unit tests #2

mjirv opened this issue Jul 14, 2021 · 0 comments · Fixed by #3
Labels
enhancement New feature or request

Comments

@mjirv
Copy link
Owner

mjirv commented Jul 14, 2021

Describe the feature

The current way of running tests is still a little more complex than I would like. We should have a simpler, more dbt-onic solution.

Specifically, one should:

  1. Be able to define the entire unit test inline under the tests block for a model in schema.yml rather than relying on global variables
  2. Be able to run unit tests alongside their other tests without having to materialize new models (other than the seeds)
  3. Not have to use any additional flags unless desired

Practically, we can use a graph node's raw_sql property along with the replace() filter and the render() function to (1) grab the raw SQL for a model, (2) replace selected refs and sources with references to our mocks, and (3) compile the resulting JinjaSQL.

Describe alternatives you've considered

I considered keeping both the previous method and the new method in the package but decided that would be too confusing.

Additional context

See discussion at dbt-labs/dbt-core#2354 and https://getdbt.slack.com/archives/C2JRRQDTL/p1623417748059300. I'm especially indebted to Josh D. and Mikael R. for these ideas and the raw_sql implementation.

Who will this benefit?

This should make it much easier for people to get started and run unit tests since they don't need to set up separate targets, runs, etc.

The main downside is that you now have to define mappings for each individual test, so it is somewhat less DRY (though there may be a way to use global variables still).

Are you interested in contributing this feature?

Yes

@mjirv mjirv added the enhancement New feature or request label Jul 14, 2021
@mjirv mjirv linked a pull request Jul 14, 2021 that will close this issue
10 tasks
@mjirv mjirv closed this as completed in #3 Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant