schireson / pytest-mock-resources

Pytest Fixtures that let you actually test against external resource (Postgres, Mongo, Redshift...) dependent code.
https://pytest-mock-resources.readthedocs.io/en/latest/quickstart.html
MIT License
179 stars 19 forks source link

Dc/multiprocess safe parallelism #129

Closed DanCardin closed 2 years ago

DanCardin commented 2 years ago

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