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

Support disabling unit tests #10831

Merged
merged 6 commits into from
Nov 6, 2024
Merged

Support disabling unit tests #10831

merged 6 commits into from
Nov 6, 2024

Conversation

tsturge
Copy link
Contributor

@tsturge tsturge commented Oct 7, 2024

Support config: disabled for unit tests. (#9109)

Also, when a model is disabled, disable the corresponding unit tests automatically. (#10540)

Problem

config:
enabled: false

Solution

Check for the config: enabled variable while parsing the unit test. If it is set to false, mark the unit test as disabled.

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.

@tsturge tsturge requested a review from a team as a code owner October 7, 2024 19:09
Copy link

cla-bot bot commented Oct 7, 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: @tsturge

Copy link
Contributor

github-actions bot commented Oct 7, 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 Oct 7, 2024
Copy link

codecov bot commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 71.42857% with 4 lines in your changes missing coverage. Please review.

Project coverage is 89.13%. Comparing base (dd77210) to head (56f2300).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10831      +/-   ##
==========================================
- Coverage   89.19%   89.13%   -0.07%     
==========================================
  Files         183      183              
  Lines       23496    23508      +12     
==========================================
- Hits        20958    20953       -5     
- Misses       2538     2555      +17     
Flag Coverage Δ
integration 86.44% <71.42%> (-0.14%) ⬇️
unit 62.11% <42.85%> (+0.02%) ⬆️

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

Components Coverage Δ
Unit Tests 62.11% <42.85%> (+0.02%) ⬆️
Integration Tests 86.44% <71.42%> (-0.14%) ⬇️

Copy link

cla-bot bot commented Oct 7, 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: @tsturge

@graciegoheen graciegoheen added the ready_for_review Externally contributed PR has functional approval, ready for code review from Core engineering label Oct 11, 2024
@devmessias
Copy link
Contributor

I like this. Especially because the unit tests are now broken when we have ctx like vars inside the model. The way I was handling this was by commenting them out.

@cla-bot cla-bot bot added the cla:yes label Oct 29, 2024
@tsturge tsturge added the artifact_minor_upgrade To bypass the CI check by confirming that the change is not breaking label Oct 29, 2024
@gshank gshank merged commit 81067d4 into main Nov 6, 2024
56 of 60 checks passed
@gshank gshank deleted the unit_test_enabled branch November 6, 2024 20:20
@maxmarcon
Copy link

Hi! I was eagerly waiting for this to be released. I saw that this PR was merged 3 weeks ago. A new dbt-core version (1.8.9) was released one week ago but this feature doesn't seem to work there yet. This unit test:

version: 2

unit_tests:
  - name: consolidate_gmv_currencies
    config: 
      enabled: false 
    model: validate_consolidate_gmv_currencies

gets still listed by dbt list

Am I missing something? Thanks

@davidbooke4
Copy link

Hi! I was eagerly waiting for this to be released. I saw that this PR was merged 3 weeks ago. A new dbt-core version (1.8.9) was released one week ago but this feature doesn't seem to work there yet. This unit test:

version: 2

unit_tests:
  - name: consolidate_gmv_currencies
    config: 
      enabled: false 
    model: validate_consolidate_gmv_currencies

gets still listed by dbt list

Am I missing something? Thanks

@maxmarcon the changes in this PR weren't included in 1.8.9, but they are included in 1.9.0. I've tested out disabling them as you have above, and it's working for me.

@davidbooke4
Copy link

davidbooke4 commented Dec 9, 2024

While explicitly disabling a unit test using the below code is working:

version: 2

unit_tests:
  - name: consolidate_gmv_currencies
    config: 
      enabled: false 
    model: validate_consolidate_gmv_currencies

I'm still getting parsing errors when a model is disabled and a unit test is not explicitly disabled:

Parsing Error
  Unable to find model 'disabled_model' for unit test 'unit_test_for_disabled_model' in ...

Whether I have the model disabled using conditional logic such as config(enabled=var('model_enabled', false) != false) or config(enabled = false) doesn't make a difference.

It seems like the unit test should be disabled in this situation based on the changes made in core/dbt/parser/unit_tests.py in this PR. It looks like the unit tests added in this PR are testing for when unit tests are disabled and not when models are disabled, but I could be wrong about that.

I'm testing this out on dbt-core v1.9.0 and dbt-bigquery v1.9.0. Please let me know if I'm doing something wrong - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
artifact_minor_upgrade To bypass the CI check by confirming that the change is not breaking 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.

6 participants