AttributeError: 'DatabaseWrapper' object has no attribute 'Database'
Question: Version numbers are Django 1.6, Python 3.3.2 and Mac OS X 10.9

I create an app with this command

    
    
     python3 manage.py startapp lists
    

Then in my lists/tests.py file I put this code

    
    
    from django.test import TestCase
    
    class SmokeTest(TestCase):
    
     def test_bad_maths(self):
        self.assertEqual(1 + 1, 3)
    

then I run this command from the app root folder

    
    
    python3 manage.py test
    

and this is the stack trace that comes back, it's not working correctly

    
    
        E
    
             ======================================================================
    ERROR: test_bad_maths (lists.tests.SmokeTest)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 124, in ensure_connection
        self.connect()
      File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 111, in connect
        conn_params = self.get_connection_params()
      File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 85, in get_connection_params
        raise NotImplementedError
    NotImplementedError
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 653, in supports_transactions
        self.connection.enter_transaction_management()
      File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 288, in enter_transaction_management
        if managed == self.get_autocommit():
      File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 324, in get_autocommit
        self.ensure_connection()
      File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 124, in ensure_connection
        self.connect()
      File "/usr/local/lib/python3.3/site-packages/django/db/utils.py", line 86, in __exit__
        db_exc_type = getattr(self.wrapper.Database, dj_exc_type.__name__)
    AttributeError: 'DatabaseWrapper' object has no attribute 'Database'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 124, in ensure_connection
        self.connect()
      File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 111, in connect
        conn_params = self.get_connection_params()
      File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 85, in get_connection_params
        raise NotImplementedError
    NotImplementedError
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/usr/local/lib/python3.3/site-packages/django/test/testcases.py", line 178, in __call__
        self._pre_setup()
      File "/usr/local/lib/python3.3/site-packages/django/test/testcases.py", line 749, in _pre_setup
        self._fixture_setup()
      File "/usr/local/lib/python3.3/site-packages/django/test/testcases.py", line 861, in _fixture_setup
        if not connections_support_transactions():
      File "/usr/local/lib/python3.3/site-packages/django/test/testcases.py", line 848, in connections_support_transactions
        for conn in connections.all())
      File "/usr/local/lib/python3.3/site-packages/django/test/testcases.py", line 848, in <genexpr>
        for conn in connections.all())
      File "/usr/local/lib/python3.3/site-packages/django/utils/functional.py", line 49, in __get__
        res = instance.__dict__[self.func.__name__] = self.func(instance)
      File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 664, in supports_transactions
        self.connection.leave_transaction_management()
      File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 317, in leave_transaction_management
        if managed == self.get_autocommit():
      File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 324, in get_autocommit
        self.ensure_connection()
      File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 124, in ensure_connection
        self.connect()
      File "/usr/local/lib/python3.3/site-packages/django/db/utils.py", line 86, in __exit__
        db_exc_type = getattr(self.wrapper.Database, dj_exc_type.__name__)
    AttributeError: 'DatabaseWrapper' object has no attribute 'Database'
    
    ----------------------------------------------------------------------
    Ran 0 tests in 0.031s
    
    FAILED (errors=1)
    


Answer: I have exact the same environment: * Mac OS X 10.9 * Python 3.3.2 * Django 1.6

I have virtualenv 1.10.1 installed and create one, install django and create
the project and app:

    
    
    virtualenv-3.3 tt
    cd tt
    . bin/activate
    pip install django==1.6
    django-admin.py startproject myproj
    cd myproj
    chmod +x manage.py
    ./manage.py startapp lists
    

Now I pasted your code into lists/test.py and run the test with the default
settings.py (database sqlite3, etc.)

    
    
    ./manage.py test
    

and got the right results:

Creating test database for alias 'default'...

    
    
    F
    ======================================================================
    FAIL: test_bad_maths (lists.tests.SmokeTest)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/erevilla/tt/myproj/lists/tests.py", line 6, in test_bad_maths
        self.assertEqual(1 + 1, 3)
    AssertionError: 2 != 3
    
    ----------------------------------------------------------------------
    Ran 1 test in 0.001s
    
    FAILED (failures=1)
    Destroying test database for alias 'default'...
    

I can't reproduce your problem. Please check:

  * settings.py (what database are you using)
  * manage.py (for incorrect version)
  * DJANGO_SETTINGS_MODULE is undefined

