Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#6515 closed (wontfix)

Django test framework requires a database

Reported by: Joe Shaw <jshaw@…> Owned by: nobody
Component: Testing framework Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


We're using Django without a database (and hence no models). We're using only views, because our web application is essentially an XML-RPC client to another server which actually contains all the data.

We'd still like to be able to use the Django's integration into unittest to test our views using django.test.client, but evidently we're required to have a database:

>>> from import execute_manager
>>> from servweb import settings
>>> execute_manager(settings, ["", "test"])
Creating test database...
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/ita/src/django/django/core/management/", line 272, in execute_manager
  File "/ita/src/django/django/core/management/", line 219, in execute
  File "/ita/src/django/django/core/management/", line 72, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/ita/src/django/django/core/management/", line 86, in execute
    output = self.handle(*args, **options)
  File "django/core/management/commands/", line 34, in handle
    failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive)
  File "django/test/", line 142, in run_tests
    create_test_db(verbosity, autoclobber=not interactive)
  File "django/test/", line 152, in create_test_db
    cursor = connection.cursor()
  File "/ita/src/django/django/db/backends/dummy/", line 14, in complain
    raise ImproperlyConfigured, "You haven't set the DATABASE_ENGINE setting yet."
django.core.exceptions.ImproperlyConfigured: You haven't set the DATABASE_ENGINE setting yet.

(Indeed, servweb.settings does not have DATABASE_ENGINE.)

We can get partial support by running the client code by hand. That is, manually setting DJANGO_SETTINGS_MODULE, importing django.test.client, and calling things like Client.get() gives us some but not all the information we'd like:

>>> r = c.get("/")
>>> print r.__dict__
{'cookies': <SimpleCookie: >, 'context': None, '_is_string': True, '_charset': 'utf-8', 
'headers': {'Content-Type': 'text/html; charset=utf-8'}, 'template': None, 'status_code': 200, '_container': [...]}

Notably, context and template are both None -- neither of them should be.

We're using 0.96.1, but I've verified this is still the case in SVN as of 2007-12-17. If you think this has been fixed more recently (a) sorry! and (b) I can update and test.

Change History (4)

comment:1 Changed 10 years ago by Joe Shaw <jshaw@…>

Possibly a dup of #3310?

comment:2 Changed 10 years ago by Russell Keith-Magee

Resolution: wontfix
Status: newclosed

There is already a way to fix this problem - write a custom test runner. The default test runner (django.test.simple.run_tests) creates a test database, finds and runs the tests, and destroys the test database. It's about 15 lines of code, and fairly straight forward. However, it can be very easily replaced with a test runner that only runs the tests. Write a test runner that doesn't create a database, and you should be set.

comment:3 Changed 10 years ago by Joe Shaw <jshaw@…>

Fair enough. Can this be added to the testing documentation? I suspect this won't be the first time this is reported without docs indicating how.

comment:4 Changed 10 years ago by Russell Keith-Magee

If you think this section can be improved, feel free to propose some additional/reworked text.

Note: See TracTickets for help on using tickets.
Back to Top