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

Pants: Use python imports to identify fixtures #6240

Merged
merged 13 commits into from
Sep 16, 2024
Merged

Conversation

cognifloyd
Copy link
Member

Background

This is part of introducing pants. 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:

  • 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 the fixture usages I missed in:

First, add metadata so pants can load the packs base path fixtures
from st2common/resources for the content laoder tests.
Second, add a fixture.py file in each base path, similar to the
fixtures we have in st2tests, so that pants dependency inferrence
can see where these fixtures are used.
Third, the fixture file ended up creating a __pycache__ directory
in the packs base paths which made tests fail due to an unexpected
extra "pack" named "__pycache__". So, I excluded that as a valid
pack name.
First, add metadata so pants can load the conf fixture from
st2common/tests/resources for the logger test.

Second, add a fixture.py file, similar to the fixtures we have in
st2tests, so that pants dependency inferrence can see where these
fixtures are used.
First, add metadata so pants can load the loadableplugin fixture
from st2common/tests/resources for the plugin loader test.

Second, add a fixture.py file, similar to the fixtures we have in
st2tests, so that pants dependency inferrence can see where these
fixtures are used.
@cognifloyd cognifloyd added this to the pants milestone Sep 14, 2024
@cognifloyd cognifloyd self-assigned this Sep 14, 2024
@pull-request-size pull-request-size bot added the size/L PR that changes 100-499 lines. Requires some effort to review. label Sep 14, 2024
@cognifloyd cognifloyd force-pushed the pants-fixture-imports branch from e744b47 to 7c74079 Compare September 14, 2024 18:20
@cognifloyd cognifloyd requested a review from a team September 14, 2024 19:45
@cognifloyd cognifloyd merged commit 63d091f into master Sep 16, 2024
29 checks passed
@cognifloyd cognifloyd deleted the pants-fixture-imports branch September 16, 2024 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infrastructure: ci/cd pantsbuild 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.

4 participants