|
|
|
|
|
by masklinn
1674 days ago
|
|
Also if you have to create new databases for each test (because, say, the data model will not allow reusing it, or you want to run tests concurrently and not all the tests are transactional) creating one as cached template then initialising test-local dbs with `createdb -T <cache>` is extremely effective. It’s also stupendously easy if you’re using pytest (though the concurrency caching is not there as IIRC xdist can’t reuse session fixtures): * create a session fixture to initialise and yield the cache db (and clean it up afterwards)
* create a regular test fixture which copies (using `createdb`) the template to a new database, and hands that off to the test Then tests which need the db just have to request the second fixture. |
|