When running tests, Django accesses the database referred to in settings
|Reported by:||Daniele Procida||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Tests that require a database (namely, model tests) will not use your "real" (production) database. Separate, blank databases are created for the tests.
There seem to be circumstances in which Django will access the real database that is referred to in settings.
Say I have a model called
I find I can't directly access the real database's
Entity objects in tests, and in most of the application code, as expected, Django doesn't find anything in
Entity.objects.all(). This is what the documentation tells me to expect.
However, in other parts of the code,
Entity.objects.all() does return the Entity objects from the real database, which surprised me. The real database is accessed before Django gets to "Creating test database for alias 'default'..."
If the real database is removed, then things behave as I would expect.
If it is to be expected that Django code when running tests will sometimes access the real database, then the documents need to explain when or how this will happen - but I don't think it should happen.
Change History (15)
comment:8 Changed 4 years ago by
|Component:||Uncategorized → Documentation|
|Triage Stage:||Unreviewed → Accepted|