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 test Jinja tag #3261

Merged
merged 3 commits into from
Apr 19, 2021
Merged

Add test Jinja tag #3261

merged 3 commits into from
Apr 19, 2021

Conversation

kwigley
Copy link
Contributor

@kwigley kwigley commented Apr 13, 2021

addresses part of #1173

Description

This PR adds a test Jinja tag. This gives us the ability to treat tests differently than very specifically defined macros. There is no change in behavior with this PR.

Checklist

  • I have signed the CLA
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt next" section.

@cla-bot cla-bot bot added the cla:yes label Apr 13, 2021
@kwigley kwigley requested review from a team, nathaniel-may and iknox-fa and removed request for a team April 13, 2021 14:37
@@ -250,9 +250,6 @@ def _inject_ctes_into_sql(self, sql: str, ctes: List[InjectedCTE]) -> str:

return str(parsed)

def _get_dbt_test_name(self) -> str:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wee, since we don't prepend tests with count(*) when "compiling" this can go away!

@kwigley kwigley requested review from gshank and jtcohen6 April 13, 2021 14:56
def get_test_macro_name(test_name, with_prefix=True):
name = f'test_{test_name}'

if with_prefix:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Use ternary here?

Copy link
Contributor

@jtcohen6 jtcohen6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is backwards compatible in a very clever way, and I had to spend a few minutes thinking about it to really get it. Nice work!

A few things worth calling out, either because I think we should eventually document them, or because it reorients my own thinking:

  • Test blocks are still technically macro nodes, just like materializations. As long as that's true, some of our other work around "configuring" generic tests (e.g. from dbt_project.yml) will have to work a bit differently. I actually think that's ok!
  • A test node named my_test cannot coexist with a macro named test_my_test. I suppose the same is true of a materialization named my_mtzn and a macro named materialization_my_mtzn.
  • If users are commonly calling other macros from within a test block, it's more likely that they will encounter the v0.19.1 regression (config() block or ref not properly accounted for), which @gshank is fixing by sticking the top-level test macro into the capture context. Once more, I think that's ok: We can tell users they need to hoist ref/source/config within the main test block to achieve the functionality they're after.

@kwigley kwigley force-pushed the feature/test-jinja-block branch 2 times, most recently from 04ba591 to a651a69 Compare April 15, 2021 14:12
Copy link
Contributor

@nathaniel-may nathaniel-may left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very slick! thanks for adding all the comments 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants