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] Exclude unit tests from running when using "dbt test" command #10656

Closed
3 tasks done
TowardOliver opened this issue Sep 3, 2024 · 2 comments · Fixed by #10706
Closed
3 tasks done

[Feature] Exclude unit tests from running when using "dbt test" command #10656

TowardOliver opened this issue Sep 3, 2024 · 2 comments · Fixed by #10706
Labels
dbt tests Issues related to built-in dbt testing functionality enhancement New feature or request unit tests Issues related to built-in dbt unit testing functionality user docs [docs.getdbt.com] Needs better documentation
Milestone

Comments

@TowardOliver
Copy link
Contributor

TowardOliver commented Sep 3, 2024

Is this your first time submitting a feature request?

  • I have read the expectations for open source contributors
  • I have searched the existing issues, and I could not find an existing issue for this feature
  • I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

Describe the feature

This is somewhat of an extension of a previous issue: #9237

Currently, including "unit_test" in the DBT_EXCLUDE_RESOURCE_TYPES env variable will prevent units from running when using the dbt build, list and clone commands. No other commands are affected by this env variable.

However, I want to extend this to include the dbt test command.

The use case is something that we're hitting currently, where we run dbt on our airflow instances; We do not want to run unit tests on our Prod airflow instances. This is recommended in the dbt docs here: https://docs.getdbt.com/docs/build/unit-tests#when-to-run-unit-tests

Some of our legacy dags / code do not utilise dbt build. Rather, they use dbt run and dbt test as separate commands.
I know that there are ways to limit what is run using specific cli commands, but I think an env variable would be much cleaner, and would prevent us from having to change our code in (potentially) multiple places.

Looking at the ticket I posted above, there seems to be an assumption that no one would want to prevent unit tests on a dbt project level, which I think is true. However, as it currently stands, preventing unit_tests on an environment level is not yet 100% achievable across all functions of dbt.

It would be ideal if we could prevent all our dbt commands from running unit tests with a single env variable, that we could set on whatever airflow instances we need.

Describe alternatives you've considered

We could change all our dags to use dbt build instead of dbt run and dbt test separately.

I believe we could also add an argument to our dbt command to something like this: dbt test --select "test_type:data".

With both these cases, we'd have to change the way we use dbt. Ideally, a global exclusion of a resource_type should be applicable to all functions of dbt.

Who will this benefit?

Anyone who wants to prevent unit tests from running on a per environment basis.

Are you interested in contributing this feature?

I am just about to create a PR for this.

Anything else?

No response

@TowardOliver TowardOliver added enhancement New feature or request triage labels Sep 3, 2024
@dbeatty10 dbeatty10 added dbt tests Issues related to built-in dbt testing functionality unit tests Issues related to built-in dbt unit testing functionality labels Sep 4, 2024
@graciegoheen graciegoheen added this to the v1.9 milestone Sep 12, 2024
@dbeatty10
Copy link
Contributor

Makes sense @TowardOliver 💡

Thanks for opening a PR for this too!

@FishtownBuildBot
Copy link
Collaborator

Opened a new issue in dbt-labs/docs.getdbt.com: dbt-labs/docs.getdbt.com#6101

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dbt tests Issues related to built-in dbt testing functionality enhancement New feature or request unit tests Issues related to built-in dbt unit testing functionality user docs [docs.getdbt.com] Needs better documentation
Projects
None yet
4 participants