Browse files

ticket #19167 test database documentation

  • Loading branch information...
evildmp committed Oct 23, 2012
1 parent 741f48c commit f0b5d1b91698452a468fd6a6af63c5b7a7d95405
Showing with 26 additions and 0 deletions.
  1. +26 −0 docs/topics/testing.txt
@@ -367,6 +367,32 @@ entirely!). If you want to use a different database name, specify
:setting:`TEST_NAME` in the dictionary for any given database in
+Note that if your code attempts to access the database when its modules are
+compiled - if you have code that executes inside a module or class when it is
+imported, rather than when a function is called - then this will occur
+*before* the test database is set up. If a real database exists, this could
+allow data from that to pollute your tests.
+It is a bad idea to have import-time database queries in your code anyway.
+Instead of referring in import-time code to the result of a database query
+ # get the base_entity, using the base_entity_id from settings
+ base_entity = Entity.objects.get(id = base_entity_id)
+create a function that when called will perform the query::
+ _base_entity = None
+ def get_base_entity():
+ if not _base_entity:
+ _base_entity = Entity.objects.get(id = base_entity_id)
+ return _base_entity
+and then call the function::
+ base_entity = get_base_entity()
Aside from using a separate database, the test runner will otherwise
use all of the same database settings you have in your settings file:
:setting:`ENGINE`, :setting:`USER`, :setting:`HOST`, etc. The test

0 comments on commit f0b5d1b

Please sign in to comment.