<Comment on #21933 Patterns for Python integration...
# github-notifications
c
Comment on #21933 Patterns for Python integration tests (e.g. w/ Postgres database) Discussion answered by peter-woyzbun What I ended up doing is using a
docker_environment
target harnessing a Docker image with Postgres installed. In my Python unit tests I can then use
pytest-postgresql
(https://github.com/dbfixtures/pytest-postgresql), which will use a subprocess to spin up a Postgres database for each test session.
Copy code
python_tests(
    # Will run tests within Docker container with Postgres installed
    environment = "py311_postgres",
    # Will make sure environment Docker image is built before running tests
    runtime_package_dependencies = ["//docker-envs/py311-postgres:image"],
    # Run tests in a single batch so we don't need multiple Postgres processes/instances
    batch_compatibility_tag = "postgres-db",
    ...
)
pantsbuild/pants