So there is a lively discussion taking place aroun...
# general
p
So there is a lively discussion taking place around pytest runners isolation. In short: we are using test containers for some database integration tests. We occasionally see things where it appears that some context is being shared across runners… even though each test spins up it’s own test container with an ephemeral port on the host. So the question is: is each pytest runner executed in isolation of all other pytest runners?
h
FWIW you can run multiple concurrent pytests natively and have them each talk to a separate database, by setting https://www.pantsbuild.org/docs/reference-pytest#execution_slot_var to point to each database
When you say "each test spins up its own test container", is that happening inside pytest?
a
In my experience
PANTS_EXECUTION_SLOT
works well for configuration that can happen outside a Docker container, e.g. testing FastAPI clients using the TestClient and such. However, from what I've been able to tell there is no way to change the environment variables of a running container without restarting it due to how processes work in Linux. This makes it difficult to test code that relies on talking to some container which then e.g. talks to a database. Since we can't update the configuration to account for the value of
PANTS_EXECUTION_SLOT
without restarting we're more or less forced to spin up a separate database for these tests alone? Has anyone found a way around this, short of creating a separate protected API endpoint that modifies some configuration file in-place which is read before every request, or something to that effect.
p
When you say "each test spins up its own test container", is that happening inside pytest?
@happy-kitchen-89482 apologies for the delay. This is correct. We either start per test or per module. Would you be able to explain the execution slot ?
@acoustic-library-86413 would be great to open another thread :)