Your thought sounds like a plausible way to get something working along the same vein as what you currently do, but I'm not sure of the details (and there might be something crucial that stops it working).
If you can change how you approach testing (I understand that this may not be possible or desirable!), pants might be able to do it more "naturally". In particular, you could potentially run tests within a
docker_environment
container (
https://www.pantsbuild.org/2.20/docs/using-pants/environments), but this won't integrate with the docker-compose services in the same way.