#21277 closed Bug (duplicate)

Running tests should not require "real" database

Reported by: tobias9 Owned by: nobody
Component: Testing framework Version: 1.5
Severity: Normal Keywords: test mysql databases
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I am trying to run tests against my django project prior to creating the "real" database used by my project. The database should not be necessary to exist to simply run tests, as it will create a test db named test_* (test_mydb in my example). This is really for the purposes of running tests in a Bamboo (or other CI) environment. This is on both a Linux Mint 15 desktop and a Ubuntu 13.04 Amazon Elastic Bamboo instance running Python 2.7.4, Django 1.5.4, and MySQL 5.5.32.

MySQL database as specified in my settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mydb',
        'USER': 'django',
        'PASSWORD': 'topsecret',
        'HOST': '',
        'PORT': '',
    }
}

Running the tests generates the following error/traceback (again, I have not created the database named 'mydb' at this point):

> python manage.py test --traceback

Creating test database for alias 'default'...
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 222, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py", line 72, in execute
    super(Command, self).execute(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 255, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py", line 89, in handle
    failures = test_runner.run_tests(test_labels)
  File "/usr/local/lib/python2.7/dist-packages/django/test/simple.py", line 370, in run_tests
    old_config = self.setup_databases()
  File "/usr/local/lib/python2.7/dist-packages/django/test/simple.py", line 315, in setup_databases
    self.verbosity, autoclobber=not self.interactive)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/creation.py", line 281, in create_test_db
    self._create_test_db(verbosity, autoclobber)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/creation.py", line 343, in _create_test_db
    cursor = self.connection.cursor()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 326, in cursor
    cursor = util.CursorWrapper(self._cursor(), self)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 406, in _cursor
    self.connection = Database.connect(**kwargs)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1049, "Unknown database 'mydb'")

Now, if I simply create the database 'mydb' without running syncdb (and/or migrate with south integration), the tests can run:

> mysqladmin --user=root --password=veryverysecret create mydb

and then run the same command above it works:

> python manage.py test --traceback

Creating test database for alias 'default'...
..................................................................................................................................................s......................................................................................................................................x.......................................................................................................................................................................................................
----------------------------------------------------------------------
Ran 481 tests in 28.853s

OK (skipped=1, expected failures=1)
Destroying test database for alias 'default'...

Change History (1)

comment:1 Changed 22 months ago by timo

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #16969

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