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

Adding logic to TestSelector to remove unit tests if they are in excluded_resource_types #10657

Conversation

TowardOliver
Copy link
Contributor

@TowardOliver TowardOliver commented Sep 3, 2024

Resolves #10656

Problem

Currently, including "unit_test" in the DBT_EXCLUDE_RESOURCE_TYPES env variable (or passing via --exclude-resource-type) will prevent unit tests from running when using the dbt build, list and clone commands ONLY.

I want to extend this to also prevent unit tests from running when using the dbt test command.

Solution

I've added a check to the TestSelector, to check the if unit_test has been set in the exclusion list. If it has, then it only allows data tests to run.

Default behaviour is to run both unit and data tests.

It's only a small / simple change. But it will get the job done of preventing unit tests from running on our Prod environments when running dbt test.

Checklist

  • I have read the contributing guide and understand what's expected of me.
  • I have run this code in development, and it appears to resolve the stated issue.
  • This PR includes tests, or tests are not required or relevant for this PR.
  • This PR has no interface changes (e.g., macros, CLI, logs, JSON artifacts, config files, adapter interface, etc.) or this PR has already received feedback and approval from Product or DX.
  • This PR includes type annotations for new and modified functions.

@TowardOliver TowardOliver requested a review from a team as a code owner September 3, 2024 12:18
Copy link

cla-bot bot commented Sep 3, 2024

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Matthew.Cooper.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

Copy link
Contributor

github-actions bot commented Sep 3, 2024

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

@github-actions github-actions bot added the community This PR is from a community member label Sep 3, 2024
@TowardOliver TowardOliver force-pushed the exclude_unit_tests_from_dbt_test branch from 38bf328 to 3e19e62 Compare September 3, 2024 12:20
Copy link

cla-bot bot commented Sep 3, 2024

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, please reach out through a comment on this PR.

CLA has not been signed by users: @TowardOliver

Copy link

cla-bot bot commented Sep 3, 2024

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, please reach out through a comment on this PR.

CLA has not been signed by users: @TowardOliver

@TowardOliver
Copy link
Contributor Author

I've just signed the CLA, so hopefully this now proceeds.

@dbeatty10 dbeatty10 changed the title Adding logic to TestSelector to remove unit tests if they are in excl… Adding logic to TestSelector to remove unit tests if they are in excluded_resource_types Sep 4, 2024
@graciegoheen graciegoheen added the ready_for_review Externally contributed PR has functional approval, ready for code review from Core engineering label Sep 12, 2024
Copy link

codecov bot commented Sep 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.89%. Comparing base (9b7f4ff) to head (4914cc9).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10657      +/-   ##
==========================================
- Coverage   88.94%   88.89%   -0.06%     
==========================================
  Files         180      180              
  Lines       22778    22783       +5     
==========================================
- Hits        20260    20252       -8     
- Misses       2518     2531      +13     
Flag Coverage Δ
integration 86.13% <100.00%> (-0.15%) ⬇️
unit 62.34% <33.33%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Unit Tests 62.34% <33.33%> (-0.01%) ⬇️
Integration Tests 86.13% <100.00%> (-0.15%) ⬇️

Comment on lines +84 to +87
# Exclude unit tests with environment variable for test command
results = run_dbt(["test", "--select", "my_model"], expect_pass=True)
assert len(results) == 0

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice @TowardOliver !

Could you do something similar just a little earlier in the file for when dbt test --exclude-resource-types unit_test? You can copy-paste-modify the section that starts with "# Run build command but specify no unit tests".

@dbeatty10
Copy link
Contributor

@cla-bot check

@cla-bot cla-bot bot added the cla:yes label Sep 12, 2024
Copy link

cla-bot bot commented Sep 12, 2024

The cla-bot has been summoned, and re-checked this pull request!

@TowardOliver
Copy link
Contributor Author

TowardOliver commented Sep 13, 2024

I've added the specific unit test you mentioned @dbeatty10 to test dbt test --exclude-resource-types unit_test.

Although I see that you've raised your own PR here: #10706
So hopefully that one goes through!

@dbeatty10
Copy link
Contributor

@TowardOliver Your PR provided the map of everything that needed to be done, plus the unit tests to verify it. 🤩 That empowered me to see how we could solve this though a refactor. Thank you!

#10706 includes your commits and also lists you as co-author to preserve the credit for your contributions.

@dbeatty10
Copy link
Contributor

Thanks again for proposing this feature in #10656 and then "showing the way" in this PR @TowardOliver 🏆 !

We just merged #10706, so closing this PR now that the feature is implemented.

@dbeatty10 dbeatty10 closed this Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes community This PR is from a community member ready_for_review Externally contributed PR has functional approval, ready for code review from Core engineering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Exclude unit tests from running when using "dbt test" command
3 participants