If you've got a database setup in Django, how can you have the TestRunner use the 'live' database (per the DATABASE_* settings in settings.py
) instead of running them on the ephemeral test database.
For example, I'd like to run the following test on the live
database that's specified in settings.py
:
import unittest
from example import models
class DBDriverTest(unittest.TestCase):
db testDriver(self):
"Connect to the live database and drop in sample value."
m = models.MyModel('hello')
m.save() # ... save to the live database from settings.py
At present the above code will save only to the test database that's been constructed. This is very limiting because my application has multiple parallel processes working on the database - and my unit tests will be incomplete (and incoherent) without the ability to pump things over to a 'live' database and see where they stand after a short sleep.
The two potential options I can think of are:
Plug through the Django API to figure out how to 'manually' connect to the database in settings.py
Make a low-level connection to the 'live' database and manually populate it
The prior is problematic because it'd be relying on things beneath Django's public API. The latter is problematic because it foregoes the database-agnostic Django database API and is more manually intensive.
I'm grateful for your thoughts and input.
Brian