-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Refactor build
test to new framework
#5134
Conversation
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. |
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.
Nothing stands out, all previous models and snapshots accounted for 👍
|
||
""" | ||
|
||
|
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.
Everything below this comment should be defined in the test file. It makes it much more clear what's happening in the tests that way. The project fixture takes care of writing all the files to the project.
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.
I've been putting the actual model strings into the test files most of the time. I tend to only have strings in this file that are extremely long or shared across multiple files. If it makes sense to do so i also split up the single giant test file into multiple files to make it easier to find and organize tests. That doesn't always make sense though, it's a different call for each set of tests, not a rule.
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.
Everything below this comment should be defined in the test file. It makes it much more clear what's happening in the tests that way.
I'm not sure I agree with that assessment. IMO it's easier to look at the test logic in one place (the test file) and the underlying project data in another file (the fixtures file). That said, I don't have strong feelings here so I'm happy to move it if it's more consistent.
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.
I hear you. I'm going to start a thread so we can decide on a standard here as a team.
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.
Just a bit more cleanup to reduce repetition.
tests/functional/build/test_build.py
Outdated
@pytest.fixture(scope="class") | ||
def snapshots(): | ||
return { | ||
"snap_1.sql": snapshots__snap_1_sql, | ||
"snap_0.sql": snapshots__snap_0_sql, | ||
"snap_99.sql": snapshots__snap_99_sql, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def tests_failing(): | ||
return { | ||
"model_2.sql": tests_failing__model_2_sql, | ||
"test.yml": tests_failing__test_yml, | ||
"model_0.sql": tests_failing__model_0_sql, | ||
"model_1.sql": tests_failing__model_1_sql, | ||
"model_99.sql": tests_failing__model_99_sql, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def models(): | ||
return { | ||
"model_2.sql": models__model_2_sql, | ||
"test.yml": models__test_yml, | ||
"model_0.sql": models__model_0_sql, | ||
"model_1.sql": models__model_1_sql, | ||
"model_99.sql": models__model_99_sql, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def models_failing(): | ||
return { | ||
"model_3.sql": models_failing__model_3_sql, | ||
"model_2.sql": models_failing__model_2_sql, | ||
"test.yml": models_failing__test_yml, | ||
"model_0.sql": models_failing__model_0_sql, | ||
"model_1.sql": models_failing__model_1_sql, | ||
"model_99.sql": models_failing__model_99_sql, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def seeds(): | ||
return {"countries.csv": seeds__countries_csv} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def models_circular_relationship(): | ||
return { | ||
"test.yml": models_circular_relationship__test_yml, | ||
"model_0.sql": models_circular_relationship__model_0_sql, | ||
"model_1.sql": models_circular_relationship__model_1_sql, | ||
"model_99.sql": models_circular_relationship__model_99_sql, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def models_simple_blocking(): | ||
return { | ||
"schema.yml": models_simple_blocking__schema_yml, | ||
"model_b.sql": models_simple_blocking__model_b_sql, | ||
"model_a.sql": models_simple_blocking__model_a_sql, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def models_interdependent(): | ||
return { | ||
"schema.yml": models_interdependent__schema_yml, | ||
"model_c.sql": models_interdependent__model_c_sql, | ||
"model_a.sql": models_interdependent__model_a_sql, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def project_files( | ||
project_root, | ||
snapshots, | ||
tests_failing, | ||
models, | ||
models_failing, | ||
seeds, | ||
models_circular_relationship, | ||
models_simple_blocking, | ||
models_interdependent, | ||
): | ||
write_project_files(project_root, "snapshots", snapshots) | ||
write_project_files(project_root, "tests-failing", tests_failing) | ||
write_project_files(project_root, "models", models) | ||
write_project_files(project_root, "models-failing", models_failing) | ||
write_project_files(project_root, "seeds", seeds) | ||
write_project_files(project_root, "models-circular-relationship", models_circular_relationship) | ||
write_project_files(project_root, "models-simple-blocking", models_simple_blocking) | ||
write_project_files(project_root, "models-interdependent", models_interdependent) |
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.
None of this is needed. Just define the models/snapshots/etc in the class. The project fixture takes care of the write_project_files()
function. I'll add an example below of what I mean.
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.
the reason we were having different folders for different model was that there could be only one set of files for the whole tests so we put everything in different folders and use model_path
to point to it. In the new test framework, we write a project repo to disk for every test class, so you can define the models
fixture that only containes files needed for current class, and not need the model_path
any more.
dbt-core/tests/functional/schema_tests/test_schema_v2_tests.py
Lines 41 to 43 in ab0c351
@pytest.fixture(scope="class") | |
def models(self, all_models): # noqa: F811 | |
return all_models["models"] |
class TestFailingBuild(BuildBase): | ||
@pytest.fixture(scope="class") | ||
def models(self, models_failing): # noqa: F811 | ||
return { | ||
"model_3.sql": models_failing["model_3.sql"], | ||
"model_2.sql": models_failing["model_2.sql"], | ||
"test.yml": models_failing["test.yml"], | ||
"model_0.sql": models_failing["model_0.sql"], | ||
"model_1.sql": models_failing["model_1.sql"], | ||
"model_99.sql": models_failing["model_99.sql"], | ||
} |
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.
Here's the example of how to define the models without everything at the top of this file.
def models(self):
return {
"model_3.sql": models_failing__model_3_sql,
"model_2.sql": models_failing__model_2_sql,
"test.yml": models_failing__test_yml,
"model_0.sql": models_failing__model_0_sql,
"model_1.sql": models_failing__model_1_sql,
"model_99.sql": models_failing__model_99_sql,
}
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.
When you import the strings this would be how you define the models fixture and can then remove the # noqa
.
Agreed with Emily's comment, just some clean up then this is good to go! |
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.
@iknox-fa Looks like one conflict to resolve otherwise looks great to me!
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.
I don't think the new manifest should be here?
We also have a pending conversation in our slack about how to approach pulling in files.
|
||
""" | ||
|
||
|
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.
I hear you. I'm going to start a thread so we can decide on a standard here as a team.
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.
There's a bit more missing with the standardization around how we format and import.
def snapshots(): | ||
return { | ||
"snap_1.sql": snapshots__snap_1_sql, | ||
"snap_0.sql": snapshots__snap_0_sql, | ||
"snap_99.sql": snapshots__snap_99_sql, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def tests_failing(): | ||
return { | ||
"model_2.sql": tests_failing__model_2_sql, | ||
"test.yml": tests_failing__test_yml, | ||
"model_0.sql": tests_failing__model_0_sql, | ||
"model_1.sql": tests_failing__model_1_sql, | ||
"model_99.sql": tests_failing__model_99_sql, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def models(): | ||
return { | ||
"model_2.sql": models__model_2_sql, | ||
"test.yml": models__test_yml, | ||
"model_0.sql": models__model_0_sql, | ||
"model_1.sql": models__model_1_sql, | ||
"model_99.sql": models__model_99_sql, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def models_failing(): | ||
return { | ||
"model_3.sql": models_failing__model_3_sql, | ||
"model_2.sql": models_failing__model_2_sql, | ||
"test.yml": models_failing__test_yml, | ||
"model_0.sql": models_failing__model_0_sql, | ||
"model_1.sql": models_failing__model_1_sql, | ||
"model_99.sql": models_failing__model_99_sql, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def seeds(): | ||
return {"countries.csv": seeds__countries_csv} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def models_circular_relationship(): | ||
return { | ||
"test.yml": models_circular_relationship__test_yml, | ||
"model_0.sql": models_circular_relationship__model_0_sql, | ||
"model_1.sql": models_circular_relationship__model_1_sql, | ||
"model_99.sql": models_circular_relationship__model_99_sql, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def models_simple_blocking(): | ||
return { | ||
"schema.yml": models_simple_blocking__schema_yml, | ||
"model_b.sql": models_simple_blocking__model_b_sql, | ||
"model_a.sql": models_simple_blocking__model_a_sql, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def models_interdependent(): | ||
return { | ||
"schema.yml": models_interdependent__schema_yml, | ||
"model_c.sql": models_interdependent__model_c_sql, | ||
"model_a.sql": models_interdependent__model_a_sql, | ||
} |
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.
You should completely remove all of this, then import the specific strings you're using instead of the fixtures in the test file.
I was not in the team meeting but my understanding was if there are more than 50 lines to define, we define them in this file but just the strings. It is the pattern I've seen with most other conversions we have done.
class TestFailingBuild(BuildBase): | ||
@pytest.fixture(scope="class") | ||
def models(self, models_failing): # noqa: F811 | ||
return { | ||
"model_3.sql": models_failing["model_3.sql"], | ||
"model_2.sql": models_failing["model_2.sql"], | ||
"test.yml": models_failing["test.yml"], | ||
"model_0.sql": models_failing["model_0.sql"], | ||
"model_1.sql": models_failing["model_1.sql"], | ||
"model_99.sql": models_failing["model_99.sql"], | ||
} |
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.
When you import the strings this would be how you define the models fixture and can then remove the # noqa
.
This PR has been marked as Stale because it has been open with no activity as of late. If you would like the PR to remain open, please comment on the PR or else it will be closed in 7 days. |
Although we are closing this PR as stale, it can still be reopened to continue development. Just add a comment to notify the maintainers. |
resolves #5128 (CT-538)
Description
Converts
build
test to new frameworkChecklist