Problem:
Today, if you run tests in multiprocess mode with python-xdist, you run the risk that the first test process to create the container "wins" by creating the container. Then later when tests are about to complete, that specific process might run out of tests first and kill the container will other processes are still running (causing test failures)
Solution:
write the container ids (produced by whichever process “wins”) to a process-safe lock file and then stop the container in the root process after tests complete
Problem: Today, if you run tests in multiprocess mode with python-xdist, you run the risk that the first test process to create the container "wins" by creating the container. Then later when tests are about to complete, that specific process might run out of tests first and kill the container will other processes are still running (causing test failures)
Solution: write the container ids (produced by whichever process “wins”) to a process-safe lock file and then stop the container in the root process after tests complete
which is essentially what they suggest in their readme https://pypi.org/project/pytest-xdist/#making-session-scoped-fixtures-execute-only-once