https://pantsbuild.org/ logo
#general
Title
# general
r

red-balloon-89377

03/20/2019, 4:32 PM
Small question: What is the best way to write an integration test that “runs pants, modifies a file (that exists in the buildroot), runs pants again”? Currently my approach is to create a
temporary_workdir():
copy the relevant target there with the same path, and run pants on that.
a

average-vr-56795

03/20/2019, 4:38 PM
Dorothy and I totally added a thing for this…
PantsRunIntegrationTest.temporary_file_content
Copy code
with self.temporary_file_content(path, content, binary_mode=False):
  pants_run = self.run_pants(command=command)
r

red-balloon-89377

03/20/2019, 4:40 PM
Ah
That is very cool!
a

average-vr-56795

03/20/2019, 4:41 PM
Oh, that one deletes the file after the run, instead of restoring its original value… I’m sure we had one for that too…
r

red-balloon-89377

03/20/2019, 4:41 PM
Wait, but I want to edit a file that exists already
a

average-vr-56795

03/20/2019, 4:42 PM
contextutil.with_overwritten_file_content
But apparently left the test method to do the writing of the new value, rather than the decorator… Could be nice to modify it to have a
temporary_contents
argument that does the writing for you too 🙂
r

red-balloon-89377

03/20/2019, 4:44 PM
Oh cool 🙂 Any idea why this is not in
PantsIntegrationTestBase
? It’s only ever used in tests
a

average-vr-56795

03/20/2019, 4:44 PM
Feel free to move it 🙂
r

red-balloon-89377

03/20/2019, 4:44 PM
Cool, that sounds like a separate PR 🙂
a

average-vr-56795

03/20/2019, 4:44 PM
Totally
r

red-balloon-89377

03/20/2019, 4:45 PM
Cool, I may have time to do that today
Also, thanks!