-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Enable --resource-type
and --exclude-resource-type
CLI flags and environment variables for dbt test
#10706
Conversation
…uded_resource_types
… associated environment variables
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #10706 +/- ##
==========================================
- Coverage 88.97% 88.96% -0.01%
==========================================
Files 181 181
Lines 22971 22979 +8
==========================================
+ Hits 20438 20443 +5
- Misses 2533 2536 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
|
--resource-type
and --exclude-resource-type
CLI flags and environment variables for dbt test
…elector` references later)
@property | ||
def resource_types(self) -> List[NodeType]: | ||
resource_types: Collection[NodeType] = resource_types_from_args( | ||
self.args, set(TEST_NODE_TYPES), set(TEST_NODE_TYPES) | ||
) | ||
|
||
# filter out any non-test node types | ||
resource_types = [rt for rt in resource_types if rt in TEST_NODE_TYPES] | ||
return list(resource_types) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def get_node_selector(self) -> ResourceTypeSelector: | ||
if self.manifest is None or self.graph is None: | ||
raise DbtInternalError("manifest and graph must be set to get perform node selection") | ||
return ResourceTypeSelector( | ||
graph=self.graph, | ||
manifest=self.manifest, | ||
previous_state=self.previous_state, | ||
resource_types=[NodeType.Test, NodeType.Unit], | ||
resource_types=self.resource_types, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…environment variables for `dbt test` (#10706) * Adding logic to TestSelector to remove unit tests if they are in excluded_resource_types * Adding change log * Respect `--resource-type` and `--exclude-resource-type` CLI flags and associated environment variables * Test CLI flag for excluding unit tests for the `dbt test` command * Satisy isort pre-commit hook * Fix mypy for positional argument "resource_types" in call to "TestSelector" * Replace `TestSelector` with `ResourceTypeSelector` * Add co-author * Update changelog description * Add functional tests for new feature * Compare the actual results, not just the count * Remove test case covered elsewhere * Test for `DBT_EXCLUDE_RESOURCE_TYPES` environment variable for `dbt test` * Update per pre-commit hook * Restore to original form (until we refactor extraneous `ResourceTypeSelector` references later) --------- Co-authored-by: Matthew Cooper <asimov.1st@gmail.com>
Resolves #10656
Alternative to #10657
Problem
Currently, the resource type CLI flags and environment variables apply to the
dbt build
,dbt list
anddbt clone
subcommands ONLY -- they do not extend todbt test
.We want to extend these to apply to the
dbt test
subcommand also.Solution
Simplify by standardizing upon the
ResourceTypeSelector
which already provides the desiredresource_types
parameter.This was accomplished by:
resource_type
andexclude_resource_type
click args to thedbt test
subcommandTEST_NODE_TYPES
list of valid test types (data tests and unit tests)resource_types
property to theTestTask
(which usesTEST_NODE_TYPES
) 👈 this was the crux!Backstory
Branched from #10657 to try an alternative approach that resolves the issue via a refactor.
Did these PRs leading up to this one:
--resource-type test
fordbt list
anddbt build
#10730TestSelector
withResourceTypeSelector
#10718Code examples
dbt
test
now enables passing values likeunit_tests
,tests
, etc. in the--resource-type
/--exclude-resource-type
CLI flags (or in the environment variablesDBT_RESOURCE_TYPES
/DBT_EXCLUDE_RESOURCE_TYPES
).Example 1 - CLI flags
Example 2 - environment variables
Documentation to update
At minimum (there may be other relevant pages):
Checklist