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
| 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.
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.
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.
| 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.
| PACK_NAME = "dummy pack 14" | ||
| PACK_DIR_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__) |
There was a problem hiding this comment.
| # 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.
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.
| 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.
| 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.
| 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.
| 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.
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.pyfile in each fixture that uses the fixturesloader utils (where helpful) to identify itself withPATHandNAMEvars.DIR_NAMEvar for the fixture packs that use a name that differs from the dir namePATH,NAMEand/orDIR_NAMEvars from that fixture.This PR focuses on only fixture packs that needed some custom bits in
fixture.pylike theDIR_NAMEvar.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 +52lines changed in test files to use the new fixture vars.