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

Repository unit tests for ManifestLoader.get_full_manifest #10147

Merged
merged 6 commits into from
May 15, 2024

Conversation

QMalcolm
Copy link
Contributor

resolves #9865

Problem

ManifestLoader.get_full_manifest is one of the central functions of dbt-core. It is what is generally used for loading the manifest. However, previously we had no unit tests for it.

Solution

Add unit tests for ManifestLoader.get_full_manifest. So in reality, get_full_manifest is more of an orchestrator method and thus offloads a fair bit of the work to other functions. We should separately ensure the sub functions get appropriately unit tested. With that said, get_full_manifest has itself some logical branches that we want to guarantee with testing. The tests we've added test these logical branches

  • usage of the reset argument
  • usage of the write_perf_info argument
  • usage of the PARTIAL_PARSE_FILE_DIFF flag

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
  • This PR includes type annotations for new and modified functions

QMalcolm added 4 commits May 14, 2024 13:45
…cation

There are a set of required mocks that `get_full_manifest` unit tests need.
Instead of doing these mocks in each test, we've abstracted these mocks into
a reusable function. I did try to do this as a fixture, but for some reaosn
the mocks didn't actually propagate when I did that.
@QMalcolm QMalcolm requested a review from a team as a code owner May 14, 2024 20:54
@cla-bot cla-bot bot added the cla:yes label May 14, 2024
@QMalcolm QMalcolm added the Skip Changelog Skips GHA to check for changelog file label May 14, 2024
Copy link

codecov bot commented May 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.64%. Comparing base (d21ff38) to head (16edcbb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10147      +/-   ##
==========================================
+ Coverage   88.58%   88.64%   +0.05%     
==========================================
  Files         180      180              
  Lines       22422    22422              
==========================================
+ Hits        19863    19876      +13     
+ Misses       2559     2546      -13     
Flag Coverage Δ
integration 86.08% <ø> (+0.12%) ⬆️
unit 62.99% <ø> (+0.12%) ⬆️

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

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

Copy link
Contributor

@ChenyuLInx ChenyuLInx left a comment

Choose a reason for hiding this comment

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

Some thoughts but otherwise LGTM

return mock_project


@pytest.fixture
Copy link
Contributor

Choose a reason for hiding this comment

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

Shoude this live somewhere in the utils being used by other unittests?

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 can lift these 👍

def set_required_mocks(
self, mocker: MockerFixture, manifest: Manifest, mock_adapter: MagicMock
):
mocker.patch("dbt.parser.manifest.get_adapter").return_value = mock_adapter
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to do the patch inside the fixture? So users of those fixtures can just request the fixture then the patch is done?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried doing so but, as noted in the commit message of 791ec1d, the mocks stopped propagating when I did so. I can take another stab at it, but can't make any promises. It definitely would be nice if we could do it as a fixture though.

Copy link
Contributor Author

@QMalcolm QMalcolm May 15, 2024

Choose a reason for hiding this comment

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

Converting it to a fixture does seem to work now. Not sure why it didn't before and why it does now 🤔 🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder whether it was not imported properly before

@QMalcolm QMalcolm requested a review from ChenyuLInx May 15, 2024 00:07
@QMalcolm QMalcolm merged commit 32a7f82 into main May 15, 2024
60 checks passed
@QMalcolm QMalcolm deleted the qmalcolm--9865-repo-unit-test-get_full_manifest branch May 15, 2024 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes Skip Changelog Skips GHA to check for changelog file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write a unittest for get_full_manifest
2 participants