Django avoids creating test database for exsting one

I have an existing database “ A ” with uploaded data that is part of another project with which I integrate. I use support for multiple Django databases and save material that I need to save in my database “ B ”, which is modeled by Django.

Now, I would like to run tests that create two test databases for me. The problem is that the test database “A” has no tables or data.

Is there a way to avoid creating a test database for " A " (which is a non-production read-only database) and use " A " directly?

+4
source share
1 answer

If I read django.test.simple.DjangoTestSuiteRunner.setup_databases , you can avoid creating a test database by specifying the 'TEST_MIRROR' parameter for your database.

This parameter is intended for checking the configuration of the master / slave , but you can achieve the expected effect if you install the mirror in the same database as the one you are setting the parameter 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 ", instead it will be replaced with its TEST_MIRROR , which is also " A ", so the tests will run " A " and " test_B " as intended.

+2
source

All Articles