diff --git a/django/db/utils.py b/django/db/utils.py index e5c4b8371b..20314495e4 100644 --- a/django/db/utils.py +++ b/django/db/utils.py @@ -114,7 +114,7 @@ def load_backend(backend_name): try: builtin_backends = [ name for _, name, ispkg in pkgutil.iter_modules([backend_dir]) - if ispkg and name != 'dummy'] + if ispkg and name not in {'base', 'dummy'}] except EnvironmentError: builtin_backends = [] if backend_name not in ['django.db.backends.%s' % b for b in diff --git a/tests/backends/test_utils.py b/tests/backends/test_utils.py new file mode 100644 index 0000000000..40a9c7b59c --- /dev/null +++ b/tests/backends/test_utils.py @@ -0,0 +1,17 @@ +from django.core.exceptions import ImproperlyConfigured +from django.db.utils import load_backend +from django.test import SimpleTestCase +from django.test.utils import str_prefix +from django.utils import six + + +class TestLoadBackend(SimpleTestCase): + def test_load_backend_invalid_name(self): + msg = str_prefix( + "'foo' isn't an available database backend.\n" + "Try using 'django.db.backends.XXX', where XXX is one of:\n" + " %(_)s'mysql', %(_)s'oracle', %(_)s'postgresql_psycopg2', %(_)s'sqlite3'\n" + "Error was: No module named %%s" + ) % "foo.base" if six.PY2 else "'foo'" + with self.assertRaisesMessage(ImproperlyConfigured, msg): + load_backend('foo')