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

Refactor build test to new framework #5134

Closed
wants to merge 12 commits into from

Conversation

iknox-fa
Copy link
Contributor

@iknox-fa iknox-fa commented Apr 21, 2022

resolves #5128 (CT-538)

Description

Converts build test to new framework

Checklist

  • I have signed the CLA
  • 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
  • I have added information about my change to be included in the CHANGELOG.

@cla-bot cla-bot bot added the cla:yes label Apr 21, 2022
@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.

@iknox-fa iknox-fa added the Skip Changelog Skips GHA to check for changelog file label Apr 21, 2022
@iknox-fa iknox-fa linked an issue Apr 21, 2022 that may be closed by this pull request
@iknox-fa iknox-fa marked this pull request as ready for review April 21, 2022 23:49
@iknox-fa iknox-fa requested a review from a team as a code owner April 21, 2022 23:49
@iknox-fa iknox-fa requested review from emmyoop and ChenyuLInx April 21, 2022 23:49
Copy link
Contributor

@stu-k stu-k left a 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 👍

tests/functional/build/test_build.py Outdated Show resolved Hide resolved
tests/functional/build/test_build.py Outdated Show resolved Hide resolved
tests/functional/build/test_build.py Outdated Show resolved Hide resolved
tests/functional/build/test_build.py Outdated Show resolved Hide resolved
tests/functional/build/test_build.py Show resolved Hide resolved

"""


Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@iknox-fa iknox-fa requested a review from emmyoop April 25, 2022 17:55
Copy link
Member

@emmyoop emmyoop left a 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.

Comment on lines 43 to 138
@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)
Copy link
Member

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.

Copy link
Contributor

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.

@pytest.fixture(scope="class")
def models(self, all_models): # noqa: F811
return all_models["models"]

Comment on lines +164 to +174
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"],
}
Copy link
Member

@emmyoop emmyoop Apr 27, 2022

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,
    }

Copy link
Member

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.

@ChenyuLInx
Copy link
Contributor

Agreed with Emily's comment, just some clean up then this is good to go!

@iknox-fa iknox-fa requested a review from emmyoop July 28, 2022 21:47
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.

@iknox-fa Looks like one conflict to resolve otherwise looks great to me!

Copy link
Member

@emmyoop emmyoop left a 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.

tests/functional/artifacts/data/state/v6/manifest.json Outdated Show resolved Hide resolved

"""


Copy link
Member

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.

@jtcohen6
Copy link
Contributor

@emmyoop @iknox-fa Is the only remaining blocker for this PR a question about how fixture data should be formatted / located in functional tests?

Copy link
Member

@emmyoop emmyoop left a 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.

Comment on lines +358 to +430
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,
}
Copy link
Member

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.

Comment on lines +164 to +174
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"],
}
Copy link
Member

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.

@github-actions
Copy link
Contributor

github-actions bot commented May 2, 2023

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.

@github-actions github-actions bot added the stale Issues that have gone stale label May 2, 2023
@github-actions
Copy link
Contributor

github-actions bot commented May 9, 2023

Although we are closing this PR as stale, it can still be reopened to continue development. Just add a comment to notify the maintainers.

@github-actions github-actions bot closed this May 9, 2023
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 stale Issues that have gone stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CT-538] 069_build_tests
5 participants