Reputation: 4594
I have an existing database "A" with data loaded, that is part of a different project that I'm integrating with. I'm using multi database Django support and storing the stuff I need to persist in my database "B" which is Django modeled.
Now I would like to run tests, which creates me two test databases. The problem is that test database "A" has no tables or data.
Is there a way to avoid creating a test database for "A" (which is a read-only non production database) and directly use "A"?
Upvotes: 4
Views: 286
Reputation: 6701
If I'm reading django.test.simple.DjangoTestSuiteRunner.setup_databases
correctly, you can avoid creating a test database by defining a 'TEST_MIRROR'
setting for your database.
The option is intended to be used for testing master/slave configuration, but you can achieve the intended effect if you set the mirror to be the same database as the one you are configuring the option on:
DATABASES = {
'A': {
'ENGINE': ..., # standard configuration goes here
'TEST_MIRROR': 'A',
},
'B': {
'ENGINE': ..., # no TEST_MIRROR, a test database will be created for B
}
}
No test database will be created for "A", it will instead be replaced by its TEST_MIRROR
, which is also "A", so the tests will run on "A" and "test_B" as intended.
Upvotes: 2