Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#6515 closed (wontfix)

Django test framework requires a database

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

Description

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 django.core.management import execute_manager
>>> from servweb import settings
>>> execute_manager(settings, ["manage.py", "test"])
Creating test database...
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/ita/src/django/django/core/management/__init__.py", line 272, in execute_manager
    utility.execute()
  File "/ita/src/django/django/core/management/__init__.py", line 219, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/ita/src/django/django/core/management/base.py", line 72, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/ita/src/django/django/core/management/base.py", line 86, in execute
    output = self.handle(*args, **options)
  File "django/core/management/commands/test.py", line 34, in handle
    failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive)
  File "django/test/simple.py", line 142, in run_tests
    create_test_db(verbosity, autoclobber=not interactive)
  File "django/test/utils.py", line 152, in create_test_db
    cursor = connection.cursor()
  File "/ita/src/django/django/db/backends/dummy/base.py", 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 by Joe Shaw <jshaw@…>, 17 years ago

Possibly a dup of #3310?

comment:2 by Russell Keith-Magee, 17 years ago

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 by Joe Shaw <jshaw@…>, 17 years ago

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 by Russell Keith-Magee, 17 years ago

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