cool-easter-32542
02/07/2025, 3:36 PMdocker-compose locally before running pants test :: (and equivalent in GitHub workflows/CI) to make a Postgres database available.
Does this seem generally possible? Is there any official stance on support (or planned support) for patterns like this? My first thought was that Pants has support for running Docker images, and for running Python tests, so maybe a plugin would work. The idea would be to have something like:
python_tests(
dependencies = [
":test_utils",
],
extra_env_vars = [
"DJANGO_SETTINGS_MODULE=tests.django_settings",
"DATABASE": "my-database"
],
docker_services=[
{"image": "<registry>/postgres:15.8", "docker_env": {"POSTGRES_DB": "my-database"}, "run_args": "...", "port": 5432}
]
)
with the complications being that:
1. Port mappings from the host to the running container would likely need to be dynamic, to prevent port clashes between parallel test runs from multiple python_tests targets requiring docker_services (e.g. if I have two python_tests targets, both requiring a Postgres database, we might need two databases running in parallel).
2. The Docker services would need to be running before tests start to run, and then torn down afterwards.
Any guidance or suggestions on how to support these types of integration tests would be appreciated.
pantsbuild/pants