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

8295 unit testing artifacts #8477

Merged
merged 28 commits into from
Aug 29, 2023

Conversation

gshank
Copy link
Contributor

@gshank gshank commented Aug 23, 2023

resolves #8295

Problem

Produce artifacts in the manifest (or elsewhere) with metadata about existing unit tests.

Solution

A dictionary of UnitTestCases is stored in manifest.unit_tests.

Selection happens against a standard manifest (filtering for UnitTestCases in manifest.unit_tests), then the unit test manifest is built with UnitTestNodes in manifest.nodes plus input models.

This pull request also implements selection of a single unit test and use of "standard" selection syntax for models.

In addition it implements partial parsing for the manifest.unit_tests.

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/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

@gshank gshank requested review from a team as code owners August 23, 2023 14:13
@gshank gshank requested review from mikealfare and QMalcolm August 23, 2023 14:13
@cla-bot cla-bot bot added the cla:yes label Aug 23, 2023
@gshank gshank marked this pull request as draft August 23, 2023 14:14
@gshank gshank requested review from MichelleArk and removed request for QMalcolm and mikealfare August 23, 2023 14:14
@gshank gshank changed the base branch from main to unit_testing_feature_branch August 23, 2023 14:16
@codecov
Copy link

codecov bot commented Aug 23, 2023

Codecov Report

Patch coverage: 89.83% and project coverage change: -0.01% ⚠️

Comparison is base (7ea7069) 86.43% compared to head (0625003) 86.42%.

Additional details and impacted files
@@                       Coverage Diff                       @@
##           unit_testing_feature_branch    #8477      +/-   ##
===============================================================
- Coverage                        86.43%   86.42%   -0.01%     
===============================================================
  Files                              176      176              
  Lines                            25914    25962      +48     
===============================================================
+ Hits                             22398    22438      +40     
- Misses                            3516     3524       +8     
Flag Coverage Δ
integration 83.26% <89.83%> (+<0.01%) ⬆️
unit 64.89% <44.38%> (+<0.01%) ⬆️

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

Files Changed Coverage Δ
core/dbt/cli/main.py 98.76% <ø> (-0.01%) ⬇️
core/dbt/cli/requires.py 94.36% <ø> (+0.17%) ⬆️
core/dbt/graph/selector_spec.py 93.54% <ø> (ø)
core/dbt/node_types.py 98.07% <ø> (ø)
core/dbt/parser/partial.py 92.36% <50.00%> (-1.06%) ⬇️
core/dbt/graph/selector_methods.py 91.20% <68.42%> (-0.29%) ⬇️
core/dbt/contracts/graph/manifest.py 93.70% <88.88%> (-0.06%) ⬇️
core/dbt/parser/unit_tests.py 89.15% <92.85%> (-2.52%) ⬇️
core/dbt/compilation.py 96.23% <100.00%> (+0.38%) ⬆️
core/dbt/constants.py 100.00% <100.00%> (ø)
... and 9 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link
Contributor

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.

@@ -31,6 +31,8 @@ def can_select_indirectly(node):
"""
if node.resource_type == NodeType.Test:
return True
elif node.resource_type == NodeType.Unit:
return True
Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding is that this is to power selection for the unit test task, but does not actually include unit tests in other task execution because UnitTestNodes are not in the manifest. Is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case the objects with NodeType.Unit are actually the UnitTestCases in manifest.unit_tests, which are in the manifest. They're not included in other tasks because each task has a Selector which filters out other resource types. So unit test cases aren't included in the "run" task job_queue because it only executes NodeType.Model.

@@ -879,14 +879,12 @@ def test(ctx, **kwargs):
@requires.project
@requires.runtime_config
@requires.manifest
@requires.unit_test_collection
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the reasoning for loading the unit test manifest (much prefer this naming to "collection"!) to the task as opposed to as a requires decorator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A requires decorator runs before the task starts. The unit test manifest can't be created until after selection is handled, which happens during task.run.

@gshank gshank marked this pull request as ready for review August 29, 2023 19:18
@gshank gshank requested a review from a team as a code owner August 29, 2023 19:18
@gshank gshank requested review from jzhu13 and removed request for a team August 29, 2023 19:18
if which and which == "unit-test":
file_name = UNIT_TEST_MANIFEST_FILE_NAME
else:
file_name = MANIFEST_FILE_NAME
Copy link
Contributor

@MichelleArk MichelleArk Aug 29, 2023

Choose a reason for hiding this comment

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

not blocking but: i think this method would be more generalized and we'd plumb fewer high-level concerns (e.g. which command is run) through to lower-level components if the optional argument was file_name instead of which -- assuming its possible to plumb the UNIT_TEST_MANIFEST_FILE_NAME itself through from the requires decorator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need it in the write_manifest call in the requires decorator. We need it in the write_manifest call from runnable.py. So we'd just have to move the "if" to the runnable "run" method, which we could certainly do, but doesn't seem like that much of an improvement. And we'd still need an "if" in the write_manifest method to determine which file name to use unless we pass the file name in every place that we call "write_manifest" which feels like overkill.

@gshank gshank merged commit 42e66fd into unit_testing_feature_branch Aug 29, 2023
@gshank gshank deleted the 8295-unit_testing_artifacts branch August 29, 2023 21:54
gshank added a commit that referenced this pull request Jan 16, 2024
* Initial implementation of unit testing (from pr #2911)

Co-authored-by: Michelle Ark <michelle.ark@dbtlabs.com>

* 8295 unit testing artifacts (#8477)

* unit test config: tags & meta (#8565)

* Add additional functional test for unit testing selection, artifacts, etc (#8639)

* Enable inline csv format in unit testing (#8743)

* Support unit testing incremental models (#8891)

* update unit test key: unit -> unit-tests (#8988)


* convert to use unit test name at top level key (#8966)

* csv file fixtures (#9044)

* Unit test support for `state:modified` and `--defer` (#9032)

Co-authored-by: Michelle Ark <michelle.ark@dbtlabs.com>

* Allow use of sources as unit testing inputs (#9059)

* Use daff for diff formatting in unit testing (#8984)

* Fix #8652: Use seed file from disk for unit testing if rows not specified in YAML config (#9064)

Co-authored-by: Michelle Ark <MichelleArk@users.noreply.github.com>
Fix #8652: Use seed value if rows not specified

* Move unit testing to test and build commands (#9108)

* Enable unit testing in non-root packages (#9184)

* convert test to data_test (#9201)

* Make fixtures files full-fledged members of manifest and enable partial parsing (#9225)

* In build command run unit tests before models (#9273)

---------

Co-authored-by: Michelle Ark <michelle.ark@dbtlabs.com>
Co-authored-by: Michelle Ark <MichelleArk@users.noreply.github.com>
Co-authored-by: Emily Rockman <emily.rockman@dbtlabs.com>
Co-authored-by: Jeremy Cohen <jeremy@dbtlabs.com>
Co-authored-by: Kshitij Aranke <kshitij.aranke@dbtlabs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CT-2922] Produce unit testing artifacts for metadata about unit testing
2 participants