﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
17421	./manage.py test trips when unit tests assume a database.	Damien Nozay	nobody	"problem statement:
- my dev setup uses 'sqlite3' backend with ':memory:' as a database
- my unit tests assume a database is setup / post_sync signals are done
- e.g. using fixtures with ContentType

settings:
{{{#!python
DATABASES = {
   'default': {
      'ENGINE': 'django.db.backends.sqlite3',
      'NAME': ':memory:'
   }
}
}}}

I get the following error:
{{{#!python
    return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: no such table: django_content_type
}}}

it trips on the fixture using contenttypes,

{{{#!python
from django.contrib.contenttypes.models import ContentType
from fixture import DataSet, DjangoFixture
#...
class Resource(DataSet):
   class Meta(object):
      django_model = 'resource.Resource'

   class host1:
      id = 1
      resource_type = ContentType.objects.get(model='host')
      resource_id = Host.host1.id

}}}


fix:

{{{#!diff
    def run_tests(self, test_labels, extra_tests=None, **kwargs):
        """"""
        Run the unit tests for all the test labels in the provided list.
        Labels must be of the form:
         - app.TestClass.test_method
            Run a single specific test method
         - app.TestClass
            Run all the test methods in a given class
         - app
            Search for doctests and unittests in the named application.

        When looking for tests, the test runner will look in the models and
        tests modules for the application.

        A list of 'extra' tests may also be provided; these tests
        will be added to the test suite.

        Returns the number of tests that failed.
        """"""
        self.setup_test_environment()
-       suite = self.build_suite(test_labels, extra_tests)
        old_config = self.setup_databases()
+       suite = self.build_suite(test_labels, extra_tests)
        result = self.run_suite(suite)
        self.teardown_databases(old_config)
        self.teardown_test_environment()
        return self.suite_result(suite, result)
}}}

"	Uncategorized	closed	Uncategorized	1.3	Normal	invalid			Unreviewed	0	0	0	0	0	0
