ApprovalTests.Python icon indicating copy to clipboard operation
ApprovalTests.Python copied to clipboard

Approvaltests not able to launch meld when running with bazel test

Open sonulohani opened this issue 5 years ago • 5 comments

Hi,

I have some approval tests which when I run using python3 command I am able to see the difference between the approved file and received file in meld. However when I am trying to do the same by running bazel test :my_approval_test I am not able to see the difference between received and approved file if the test fails as the process is getting killed before even started. I have tried using --spawn_strategy=local also however that also doesnt work.

sonulohani avatar Feb 05 '21 06:02 sonulohani

I could use subprocess.run instead of subprocess.Popen, however the method run_command is static in GenericDiffReporter and I am not able to modify the behaviour.

sonulohani avatar Feb 05 '21 06:02 sonulohani

Did you have the chance to look at this a bit more? If run works but Popen doesn't in your context (I don't know bazel and don't know what it does), it would be a good idea to first check why this happens. The only difference I am aware of between run and Popen is that run is blocking. But the non blocking launch does work in other context and that is also the idea. So what does bazel do differently?

obestwalter avatar Feb 08 '21 10:02 obestwalter

Did you have the chance to look at this a bit more? If run works but Popen doesn't in your context (I don't know bazel and don't know what it does), it would be a good idea to first check why this happens. The only difference I am aware of between run and Popen is that run is blocking. But the non blocking launch does work in other context and that is also the idea. So what does bazel do differently?

The problem is that the bazel runs all its tasks in its own sandbox so whenever bazel is done with running the test cases it closes its server and due to that whatever the processes running inside bazel also get killed. The run works because it blocks the bazel workflow by stopping/blocking the execution context until the diffviewer gets closed or killed. I temporarily fixed it by making custom reporter class derived from GenericDiffReporter and overriding the report method and using run instead of Popen. It kind of works because the entire purpose is to see the diff of the failed test cases.

sonulohani avatar Feb 08 '21 11:02 sonulohani

Interesting. So that means though that there definitely is a case to be made for setting the spawning of the differ to be blocking, maybe as a command line argument. I am quite new to the tool as a user but also have a vague feeling that I would prefer the blocking workflow even when running approvals normally. Opened #95 for that.

obestwalter avatar Feb 08 '21 19:02 obestwalter

Hi @obestwalter You're right. Right now I am controlling the behaviour using "use_custom_reporter" as command line parameter because I want to run the same test in ci server as well and if I get test failure then I wouldn't need diff viewer to be opened in the server.

sonulohani avatar Feb 09 '21 02:02 sonulohani