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

create a happy path project fixture #10291

Merged
merged 6 commits into from
Jun 11, 2024
Merged

create a happy path project fixture #10291

merged 6 commits into from
Jun 11, 2024

Conversation

ChenyuLInx
Copy link
Contributor

@ChenyuLInx ChenyuLInx commented Jun 10, 2024

resolves #10256

Problem

We are missing a central place to define a happy path project that contains a bit of everything to be reused across different tests.

Solution

We are adding a happy_path_project fixture that will give integration tests a project to use

  • I had to refactor the project construction a little bit to make using happy path project a bit more obvious and intuiative
  • I choose to use normal file folder instead of using string defined in code to improve local testing experience and readability.

@ChenyuLInx ChenyuLInx requested a review from a team as a code owner June 10, 2024 23:48
@cla-bot cla-bot bot added the cla:yes label Jun 10, 2024
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.

Copy link

codecov bot commented Jun 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.71%. Comparing base (4df120e) to head (8839cfb).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10291      +/-   ##
==========================================
- Coverage   88.74%   88.71%   -0.03%     
==========================================
  Files         180      180              
  Lines       22495    22483      -12     
==========================================
- Hits        19963    19946      -17     
- Misses       2532     2537       +5     
Flag Coverage Δ
integration 85.97% <100.00%> (-0.11%) ⬇️
unit 61.70% <80.00%> (-1.51%) ⬇️

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.

@ChenyuLInx ChenyuLInx added the Skip Changelog Skips GHA to check for changelog file label Jun 10, 2024
Copy link
Contributor

@QMalcolm QMalcolm left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thank you for doing this work 🙂

I do have some questions in regards to how things changed. They aren't blocking questions, but I'd like to discuss them so I can better understand how the code is functioning. Most of these occur in the fix commits. It'd be amazing to have some of that context in the commit messages themselves.

core/dbt/tests/fixtures/project.py Show resolved Hide resolved
@@ -56,7 +42,7 @@ def expect_given_output(self, args, expectations):
else:
assert got == expected

def expect_snapshot_output(self, project):
def expect_snapshot_output(self, happy_path_project): # noqa: F811
Copy link
Contributor

Choose a reason for hiding this comment

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

In this test we're actually using the happy_path_project fixture argument in the function. Is the # noqa: F811 necessary for another reason?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, also curious about this

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 think for whatever reason flake8 was complaining about all of these in my local dev environment.
Let me try again and see what happened here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the problem with pytest, I don't see a easy way of getting rid of it.
https://stackoverflow.com/questions/50268284/why-im-getting-f811-error-in-this-code

@@ -724,12 +710,12 @@ def expect_resource_type_env_var(self):
}
del os.environ["DBT_EXCLUDE_RESOURCE_TYPES"]

def expect_selected_keys(self, project):
def expect_selected_keys(self, happy_path_project): # noqa: F811
Copy link
Contributor

@QMalcolm QMalcolm Jun 11, 2024

Choose a reason for hiding this comment

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

In this test we're actually using the happy_path_project fixture argument in the function. Is the # noqa: F811 necessary for another reason?

Comment on lines 601 to 603
project_files,
project_setup: TestProjInfo,
project_files,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not asking for a change here, but I would like to understand the context. Does the ordering of the fixture arguments here mean something? Is there a reason the project_setup fixture has to be come before project_files? This is the kind of thing I would love to see in a commit comment so that I can better understand why something is changing while reviewing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, adding a comment in the following commit.
The order of the argument determines the order of fixtures being executed(if they need to).
So we do all setups, then write the project files. Setup should be independent of project file write.

Another reason is for the happy path fixture, we do not use the dbt_project.yml fixture, instead, we want to use the files in the fixture folder, changing the order makes sure that the tests run with the intended files

Comment on lines 89 to 97
@pytest.fixture(scope="class")
def project_files(
project_root,
tests,
models,
selectors_yml,
):
write_project_files(project_root, "tests", tests)
write_project_files(project_root, "models", models)
Copy link
Contributor

Choose a reason for hiding this comment

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

Were we able to remove this because of the existing more widely available project_files satisfied the relevant tests? I'm trying to understand if this is extraneous cleanup or if it was necessary for some reason in regards to the happy path testing we are setting up in this branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, they are covered by the project_files.
And the reason they are being removed is they failed to write certain files(like dbt_project.yml), they might not be relevant anymore with the order of writing project files but I think it is still good to remove.

@@ -0,0 +1,8 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

super nit: looks like a lot of these files have an extra empty line at the top of the file, could we clean that up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good!

Copy link
Contributor

@MichelleArk MichelleArk left a comment

Choose a reason for hiding this comment

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

Not necessarily blocking but I would like to understand the necessity for the new # noqa: F811 usages with happy_path_project since we'll probably start seeing those all over the place once we migrate more tests to using happy_path_project.

@ChenyuLInx ChenyuLInx requested review from QMalcolm and a team June 11, 2024 20:41
@ChenyuLInx ChenyuLInx merged commit e699f5d into main Jun 11, 2024
63 checks passed
@ChenyuLInx ChenyuLInx deleted the cl/10256 branch June 11, 2024 21:41
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.

Create "happy path" project fixture and use it for tests/functional/list/test_list.py
3 participants