Patterns for Python integration tests (e.g. w/ Postgres database) #21933
-
| I have some Django applications I am looking to onboard to a monorepo that uses Pants. These applications depend on Postgres-specific database features, e.g. triggers, and so tests require a running Postgres database (vs. just using SQLite). Ideally these tests could run within Pants/hermetically - i.e. without having to run something like  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: with the complications being that: 
 Any guidance or suggestions on how to support these types of integration tests would be appreciated. | 
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
| This is a massive amount of work and I would imagine it is probably outside of the scope of Pants core. In my organization we use a separate tool for what you are describing, lets call them integration tests. I think there are opportunities for integrating these different kinds of tools, but they can be used in harmony together today. For instance I would use garden to set up the testing environment and then pants inside the container to run the tests and it can then efficiently only run tests for the effected modules. On the other hand we might use Pants to tell Garden which integration test jobs need rerun from doing a dependency analysis, via a Pants plugin. Hope some of my experience helped. | 
Beta Was this translation helpful? Give feedback.
-
| What I ended up doing is using a   | 
Beta Was this translation helpful? Give feedback.
What I ended up doing is using a
docker_environmenttarget harnessing a Docker image with Postgres installed. In my Python unit tests I can then usepytest-postgresql(https://github.com/dbfixtures/pytest-postgresql), which will use a subprocess to spin up a Postgres database for each test session.