Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#26270 closed Bug (invalid)

testing framework requires database configuration from lean databaseless project

Reported by: Herbert Owned by: nobody
Component: Testing framework Version: 1.9
Severity: Normal Keywords: database
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Herbert)

Create django project and application and remove some superfluous files:

django-admin startproject foo
cd foo/
django-admin startapp bar
rm -rf bar/migrations/ bar/models.py  bar/apps.py bar/admin.py foo/wsgi.py 

Changed the files to look like this:

# foo/settings.py
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = '1234'
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = [ 'bar' ]
MIDDLEWARE_CLASSES = []
ROOT_URLCONF = 'foo.urls'
DATABASES = {}
# foo/urls.py
from django.conf.urls import url
from bar.views import my_oh_my

urlpatterns = [
    url(r'^$', my_oh_my),
]
# bar/tests.py
from django.test import TestCase

class TestFoo(TestCase):
    def test_foo(self):
        assert True
        print('tested!')
# bar/views.py
from django.shortcuts import render
from django.http.response import HttpResponse

def my_oh_my(request):
    return HttpResponse('my, oh, my!')

Both foo and bar have an empty __init__.py. Running this project as a server is fine, however testing it results in this error:

# python3 manage.py test
tested!
.E
======================================================================
ERROR: test_foo (bar.tests.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/herbert/.local/lib/python3.4/site-packages/django/test/testcases.py", line 217, in __call__
    self._post_teardown()
  File "/home/herbert/.local/lib/python3.4/site-packages/django/test/testcases.py", line 919, in _post_teardown
    self._fixture_teardown()
  File "/home/herbert/.local/lib/python3.4/site-packages/django/test/testcases.py", line 1072, in _fixture_teardown
    return super(TestCase, self)._fixture_teardown()
  File "/home/herbert/.local/lib/python3.4/site-packages/django/test/testcases.py", line 955, in _fixture_teardown
    inhibit_post_migrate=inhibit_post_migrate)
  File "/home/herbert/.local/lib/python3.4/site-packages/django/core/management/__init__.py", line 119, in call_command
    return command.execute(*args, **defaults)
  File "/home/herbert/.local/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/herbert/.local/lib/python3.4/site-packages/django/core/management/commands/flush.py", line 49, in handle
    allow_cascade=allow_cascade)
  File "/home/herbert/.local/lib/python3.4/site-packages/django/core/management/sql.py", line 15, in sql_flush
    tables = connection.introspection.django_table_names(only_existing=True, include_views=False)
  File "/home/herbert/.local/lib/python3.4/site-packages/django/db/backends/base/introspection.py", line 86, in django_table_names
    existing_tables = self.table_names(include_views=include_views)
  File "/home/herbert/.local/lib/python3.4/site-packages/django/db/backends/base/introspection.py", line 56, in table_names
    with self.connection.cursor() as cursor:
  File "/home/herbert/.local/lib/python3.4/site-packages/django/db/backends/base/base.py", line 233, in cursor
    cursor = self.make_cursor(self._cursor())
  File "/home/herbert/.local/lib/python3.4/site-packages/django/db/backends/dummy/base.py", line 21, in complain
    raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

----------------------------------------------------------------------
Ran 1 test in 0.002s

FAILED (errors=1)

It states that I need to better configure the DATABASES variable, which I think is not adequate.

django.__version__ == '1.9.2'

Attachments (1)

foo.tar (8.5 KB ) - added by Herbert 8 years ago.
project files

Download all attachments as: .zip

Change History (8)

by Herbert, 8 years ago

Attachment: foo.tar added

project files

comment:1 by Herbert, 8 years ago

Description: modified (diff)

comment:2 by Tim Graham, 8 years ago

Please try with SimpleTestCase instead TestCase as the latter does require a database.

comment:3 by Herbert, 8 years ago

You are right!

Perhaps, a pointer to SimpleTestCase could be provided here:

https://docs.djangoproject.com/en/1.9/topics/testing/tools/#django.test.TestCase

Last edited 8 years ago by Herbert (previous) (diff)

comment:4 by Tim Graham, 8 years ago

Resolution: invalid
Status: newclosed

I agree those docs could be better organized: PR

comment:5 by Tim Graham <timograham@…>, 8 years ago

In 7a7e4033:

Refs #26270 -- Reorganized TestCase docs.

comment:6 by Herbert, 8 years ago

Thank you! I obviously enjoyed the rest of Django very much :)

comment:7 by Tim Graham <timograham@…>, 8 years ago

In d7881bfa:

[1.9.x] Refs #26270 -- Reorganized TestCase docs.

Backport of 7a7e403325427642905a5b3e26931c2b8e92d4b1 from master

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