I'm trying to speed up the Selenium tests in my python Django web application by using parallel execution of 4 threads (-n=4)
Of the first 4 tests, 3 give the following error:
[test setup] [Test Error Output]
Got an error creating the test database: (1007, "Can't create database 'test1database'; database exists")
I get that I have to specify setup to be run once before parallel test execution, to prevent this multiple attempts at creating the database, but how would I enforce this in pytest xdist configuration?
You can probably have a different database for each one of the threads. The
worker_id
fixture allows you to do that https://github.com/pytest-dev/pytest-xdist#identifying-the-worker-process-during-a-testUpdate
This github issue comment shows a solution to the OP's original problem. It also creates N databases, using a shared template. This brings the interesting twist of synchronizing the access to a shared resource in fixture.