-
-
Notifications
You must be signed in to change notification settings - Fork 752
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 4/6) #5704
Conversation
769d0c8
to
e7135b0
Compare
e7135b0
to
8bb4b2b
Compare
30c2b0e
to
a13542a
Compare
8bb4b2b
to
417794e
Compare
417794e
to
f4a651b
Compare
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.
LGTM Overall, had a minor question below
self.assertEqual(len(resp.json), 1) | ||
self.assertEqual(resp.json[0]["file_path"], "pack.yaml") | ||
self.assertEqual(len(resp.json), 3) | ||
self.assertIn("pack.yaml", [f["file_path"] for f in resp.json]) |
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.
What does this change?
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 pack in question only had pack.yaml
before this PR. I added fixture.py
and __init__.py
, so the file count goes up to 3.
And, since there is more than one file, we can't just assume that the resp.json[0]
is the pack.yaml
file. But is it [1]
or [2]
? It's hard to say because the order might depend on the the filesystem. I tried resp.json[2]
which on GHA was not pack.yaml
, so they are not sorted alphabetically. To avoid a flaky test relying on a particular sort, I made a list of the files with [f["file_path"] for f in resp.json]
, and just assert that pack.yaml
is in it.
a13542a
to
216129e
Compare
f4a651b
to
fba1c80
Compare
fba1c80
to
8283904
Compare
PACK_NAME = "test_content_version" | ||
_, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__) | ||
PACK_PATH = PACK_PATH[: -len("_fixture")] |
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 test_content_version
fixture is in a git submodule. I wanted to keep all the fixture details in this repo so that they're available even if someone has not cloned the submodule. So, I put the fixture vars in test_content_version_fixture
directory and adjusted the vars.
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 are the sources for many of the pack fixture changes. (FYI - for anyone needs to reference this in the future)
PACK_NAME = "dummy_pack_10_wrong_deps" | ||
PACK_DIR_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__) |
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.
name : dummy_pack_10_wrong_deps |
PACK_NAME = "dummy pack 14" | ||
PACK_DIR_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__) |
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.
name : dummy pack 14 |
# limitations under the License. | ||
from st2tests import fixturesloader | ||
|
||
PACK_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__) |
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.
This one did not need special vars. Instead, it needed special handling in one of the tests that counted the number of files in the pack.
PACK_NAME = "Dummy Pack 18" | ||
PACK_DIR_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__) |
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.
name : Dummy Pack 18 |
PACK_NAME = "dummy_pack_7_name" | ||
PACK_DIR_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__) |
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.
name : dummy_pack_7_name |
PACK_NAME = "Dummy Pack 8 Invalid Name" | ||
PACK_DIR_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__) |
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.
name : Dummy Pack 8 Invalid Name |
PACK_NAME = "dummy_pack_9_deps" | ||
PACK_DIR_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__) |
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.
name : dummy_pack_9_deps |
PACK_NAME = "pack_name_not_the_same_as_dir_name" | ||
PACK_DIR_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__) |
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.
st2/st2tests/st2tests/fixtures/packs/pack_dir_name_doesnt_match_ref/pack.yaml
Lines 1 to 2 in 6db0561
ref: pack_name_not_the_same_as_dir_name | |
name: pack_name_not_the_same_as_dir_name |
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:
__init__.py
.fixture.py
file in each fixture that uses the fixturesloader utils (where helpful) to identify itself withPATH
andNAME
vars.DIR_NAME
var for the fixture packs that use a name that differs from the dir namePATH
,NAME
and/orDIR_NAME
vars from that fixture.This PR focuses on only fixture packs that needed some custom bits in
fixture.py
like theDIR_NAME
var.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:
fixture.py
(~16 lines, 13 of which are copyright/license header):18+17*3+16=+85 lines
(-1 +2)*5=(-5 +10)
-47 +52
lines changed in test files to use the new fixture vars.