Avoid selecting production database prior to test database setup/teardown
|Reported by:||andreas_pelme||Owned by:||nobody|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I am playing around with running my test suite with pytest and pytest-xdist. I would like to be able to run my tests in parallell, which would probably be a massive speedup on a decent multi-core CPU. To isolate tests properly, I am dynamically modifying the database name in the settings, to create a separate test database for each process.
However, when the test database is created, Django creates a cursor to the production database before setting up/destroying the test database. Since I am generating the database name dynamically in each process, this causes problems for me, since I do not know the name and can create it beforehand. I see no reason for doing this, so I would like to skip selecting the production database before creating/destroying the test database.
The behavior is when creating a cursor without specifying a database varies a bit across the backends:
- sqlite - this is not a problem
- mysql - it is possible to omit the database name
- postgesql - a database name must be given, but rather than choosing the production name, the default "postgesql" database can be used
- oracle - I am unable to test this since I do not have an Oracle database available
I have modified django/db/backends/creation.py to set connection.settings_dictNAME? to None instead of the production database name during creation/destroy. I also made a small change in the postgres backend to use the "postgesql" database if None is supplied.
I have run the Django test suite for sqlite, mysql and postgesql and this does not seems to cause any problems.
Change History (17)
Changed 4 years ago by andreas_pelme
comment:1 Changed 4 years ago by carljm
- Has patch set
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
Changed 20 months ago by claudep
comment:11 Changed 19 months ago by Claude Paroz <claude@…>
- Resolution set to fixed
- Status changed from new to closed