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

Use python imports to identify fixtures (part 3/6) #5703

Merged
merged 5 commits into from
Aug 17, 2022

Conversation

cognifloyd
Copy link
Member

@cognifloyd cognifloyd commented Aug 11, 2022

Background

I'm working towards introducing pants. Eventually I would like to use pants to run tests to take advantage of the fine-grained per-file caching of results that accounts for dependencies by python files (pants infers the deps by reading the python files).

In order to use the fine-grained caching, Pants needs to know which tests rely on which fixtures. We could add extra metadata to tie the tests to the fixtures, but that would be an additional maintenance burden that will become out-of-date. We can also include all fixtures for all tests, but then we don't benefit from the fine-grained per-file caching. However, pants can already infer dependencies based on python imports, so that is what this PR (and several follow-up PRs) takes advantage of.

Overview

This PR does the following:

  • adjust util in st2tests/st2tests/fixturesloader.py so that we can use those utilities to identify pack fixtures in directories outside of st2tests/st2tests/fixtures/packs.
  • turn every fixture into an importable python module with an __init__.py.
  • add a fixture.py file in each fixture that uses the fixturesloader utils (where helpful) to identify itself with PATH and NAME vars.
  • in every test that uses a given fixture, import PATH and/or NAME vars from that fixture.

This PR focuses on only fixture packs that are in: st2tests/st2tests/fixtures/packs_1/, st2tests/st2tests/fixtures/packs_invalid/ and st2tests/st2tests/fixtures/.
Follow-up PRs will address other fixture packs and other sets of fixtures. I will submit those PRs after this one is merged.

Statistics

Changes Summary:

  • 1 line updated in changelog
  • 3 lines changed in st2tests/st2tests/fixturesloader.py
  • 11 copies of fixture.py (16 lines, 13 of which are copyright/license header): 16*11=+176 lines
  • -103 +93 lines changed in test files to use the new fixture vars.
  • -6 lines: remove unused vars in one test file

@cognifloyd cognifloyd added this to the 3.8.0 milestone Aug 11, 2022
@cognifloyd cognifloyd self-assigned this Aug 11, 2022
@pull-request-size pull-request-size bot added the size/XXL PR that changes 1000+ lines. You should absolutely split your PR into several. label Aug 11, 2022
@cognifloyd cognifloyd force-pushed the fixtures-loading-3 branch 3 times, most recently from 23ac68d to e3ca0a5 Compare August 11, 2022 04:13
@cognifloyd cognifloyd changed the base branch from master to fixtures-loading-2 August 11, 2022 05:04
@pull-request-size pull-request-size bot added size/L PR that changes 100-499 lines. Requires some effort to review. and removed size/XXL PR that changes 1000+ lines. You should absolutely split your PR into several. labels Aug 11, 2022
@cognifloyd cognifloyd changed the base branch from fixtures-loading-2 to master August 11, 2022 16:30
@pull-request-size pull-request-size bot added size/XXL PR that changes 1000+ lines. You should absolutely split your PR into several. and removed size/L PR that changes 100-499 lines. Requires some effort to review. labels Aug 11, 2022
@cognifloyd cognifloyd changed the base branch from master to fixtures-loading-2 August 11, 2022 19:05
@pull-request-size pull-request-size bot added size/L PR that changes 100-499 lines. Requires some effort to review. and removed size/XXL PR that changes 1000+ lines. You should absolutely split your PR into several. labels Aug 11, 2022
@cognifloyd cognifloyd changed the base branch from fixtures-loading-2 to master August 11, 2022 19:23
@pull-request-size pull-request-size bot added size/XXL PR that changes 1000+ lines. You should absolutely split your PR into several. and removed size/L PR that changes 100-499 lines. Requires some effort to review. labels Aug 11, 2022
@cognifloyd cognifloyd changed the base branch from master to fixtures-loading-2 August 11, 2022 20:40
@pull-request-size pull-request-size bot added size/L PR that changes 100-499 lines. Requires some effort to review. and removed size/XXL PR that changes 1000+ lines. You should absolutely split your PR into several. labels Aug 11, 2022
@cognifloyd cognifloyd changed the title Use python imports to identify fixtures (part 3) Use python imports to identify fixtures (part 3/6) Aug 11, 2022
@cognifloyd cognifloyd requested a review from rush-skills August 12, 2022 15:48
Copy link
Member

@rush-skills rush-skills left a comment

Choose a reason for hiding this comment

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

LGTM

Base automatically changed from fixtures-loading-2 to master August 17, 2022 11:16
@pull-request-size pull-request-size bot added size/XXL PR that changes 1000+ lines. You should absolutely split your PR into several. and removed size/L PR that changes 100-499 lines. Requires some effort to review. labels Aug 17, 2022
@pull-request-size pull-request-size bot added size/L PR that changes 100-499 lines. Requires some effort to review. and removed size/XXL PR that changes 1000+ lines. You should absolutely split your PR into several. labels Aug 17, 2022
@cognifloyd cognifloyd marked this pull request as ready for review August 17, 2022 15:22
@cognifloyd cognifloyd requested a review from a team August 17, 2022 15:22
@cognifloyd cognifloyd enabled auto-merge August 17, 2022 15:33
Comment on lines -336 to -341
FIXTURES_PACK = "generic"
TEST_FIXTURES = {
"runners": ["testrunner1.yaml"],
"actions": ["action1.yaml", "local.yaml"],
}

Copy link
Member Author

Choose a reason for hiding this comment

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

These vars are unused. So I removed them.

Comment on lines 172 to +175
def get_fixture_name_and_path(fixture_file):
pack_name = os.path.basename(os.path.dirname(fixture_file))
pack_path = os.path.join(get_fixtures_packs_base_path(), pack_name)
return pack_name, pack_path
fixture_path = os.path.dirname(fixture_file)
fixture_name = os.path.basename(fixture_path)
return fixture_name, fixture_path
Copy link
Member Author

@cognifloyd cognifloyd Aug 17, 2022

Choose a reason for hiding this comment

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

I adjusted this method to make it more generic, so we can use it for pack fixtures that are not in st2tests/st2tests/fixtures/packs.

I also renamed the vars to highlight that this is not specific to packs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement maintenance pantsbuild refactor size/L PR that changes 100-499 lines. Requires some effort to review. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants