I’d like to use lock files in a JVM test to avoid ...
# development
f
I’d like to use lock files in a JVM test to avoid having to code a whole bunch of jar metadata into Python code. Is there a preferred way to be able to generate and use lock files in that manner?
essentially the lock file would be a test fixture
h
Like load it as a resource?
f
exactly
h
No prior convention
f
to clarify, it wouldn’t be a python resource, just a test fixture for the test
my question is really on how to trigger regenerating the lockfile
since test code should not be hooked up into the
generate-lockfiles
goal
That is, manually generate it. When manually generating, set this option so that future readers know how to manually regenerate
f
right but that would still mean having a LockfileSentinnel (or whatever it is called) for tests,
h
What are you testing? If it's a real tool, can you coerce the options for pants to generate a lock file for that tool
f
versus having a script that could use a
RuleRunner
to invoke the correct logic and write out the lock file
it’s for various JVM tests where we currently hard-code a whole bunch of artifacts
via
TestCoursierWrapper
updating those artifacts is a chore which had me copying SHA-256 hashes into Python after manually running
sha256sum
👍 1
trying to avoid that chore
h
Rule runner cannot write to the build root, but I think that you can manipulate things like
Path(get_buildroot())
maybe
f
well a helper script that does a resolve via
RuleRunner
and then gets some output it writes to disk outside of the engine could work
coke 1
h
or use a pex_binary script to generate fixtures?
Yeah that sounds better. I was envisioning doing it within the test goal, but that's a horrible idea
f
yeah no, these are test fixtures that should only be read during tests
otherwise we would sort of invalidate the test by having the fixtures potentially vary during the test
👍 1
I was thinking that tests could declare the artifacts for their lock file via annotations read by the external regeneration script.
any way, good discussion with some ideas for me to move forward with. thanks!
❤️ 1
h
Thank you for thinking this through! FYI this is an issue with Python too, only that we punt around it because Python is much more generous with letting you not have a lock file
f
how would I specify in a BUILD file that the regeneration script depends on all of
src/pants/python::
?
I want to be able to run the pytest test collection algorithm to gather the tests and then inspect them for the custom decorator that I have defined caling for a lockfile.
pytets can do that if I find a way to bring all of the python files into the execution sandbox
f
does that include test files though?
h
dont directly use the python_distribution - it would result in pants first building the dist
does that include test files though?
no
f
yeah I need the test files so pytest can introspect them …
h
f
I can just have deps directly on test directories with known lockfiles.
adding a lockfile in another dir will require adding it to the deps list, which is fine for now.
coke 1
h
I want to be able to run the pytest test collection algorithm to gather the tests and then inspect them for the custom decorator that I have defined caling for a lockfile. (
Can you simply hardcode it? Less magical, but avoids a wild goose chase
f
yes I just said that
h
coke == ditto. I sent before seeing you said that
f
👍
async communication pretending to be real time …
🔥 1
🙂
@hundreds-father-404: would love your input on the approach so far, especially around BUILD file stuff