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

Fix for custom generic tests #211

Merged
merged 4 commits into from
Jul 10, 2024
Merged

Fix for custom generic tests #211

merged 4 commits into from
Jul 10, 2024

Conversation

dave-connors-3
Copy link
Collaborator

@dave-connors-3 dave-connors-3 commented May 29, 2024

When someone creates a custom generic test, it gets rendered as a macro in the manifest. this means that when we compile all the macros in the project during startup of the group and split commands, we fail to find the correct test block.

this PR

  • updates the args to the JinjaBlock.from_file call to be test and trims test_ (which dbt adds) to find the name of the custom generic test block when the macro path is under tests/generic/
  • adds a custom generic test to the split project to ensure this logic works!

submitted in partial fulfillment of #210

Copy link
Collaborator

@nicholasyager nicholasyager left a comment

Choose a reason for hiding this comment

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

@dave-connors-3 The code in this PR makes sense for the most part. I had one small question about the use of test/generic/ vs the test-path value in dbt_project.yml. Once that's sorted, we should be good to move forward.

Comment on lines 335 to 337
if "tests/generic/" in macro.path:
block_type = "test"
name = macro.name[5:]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't feel super confident in using this hard-coded path. Would it make sense to use the test directory provided in dbt_project.yml here instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that makes sense to me! will update

@@ -140,7 +140,7 @@ def models(self) -> Dict[str, ModelNode]:
return self._models

self._models = {
node_name: node
node_name: node # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍🏻


blocks[unique_id] = JinjaBlock.from_file(
path=self.path / macro.original_file_path, block_type="macro", name=macro.name
path=self.path / macro.original_file_path, block_type=block_type, name=name
Copy link
Collaborator

Choose a reason for hiding this comment

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

I really like that this function has been parameterized 👍🏻 🪨

Copy link
Collaborator

@nicholasyager nicholasyager left a comment

Choose a reason for hiding this comment

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

@dave-connors-3 One minor question about the index variable. Otherwise should be good to 🚢

Comment on lines +338 to +340
top_level_folder in self.project.test_paths
if self.project.test_paths
else ["tests"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Beautiful logic 🪨

else ["tests"]
):
block_type = "test"
index = len(top_level_folder)
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is index being used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah wait that's wrong -- the 5 should still be hardcoded to remove test_from the name of the macro to properly search the jinja for my_test and not test_my_test

Copy link
Collaborator

@nicholasyager nicholasyager Jul 10, 2024

Choose a reason for hiding this comment

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

Yes! That makes sense 👍🏻

@dave-connors-3 dave-connors-3 merged commit 9a1efa1 into main Jul 10, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants