2

単体テストを実行しようとすると、データベースでテーブルが利用できないというエラーが表示されます。私のテストは 1 日前まで問題なく実行されていましたが、それ以降に変更した内容についてブレインストーミングを行っても、この問題の原因に近いものは思い浮かびません。

これは、データベースにテーブルを適切に作成していないことに問題があるsyncdbと考えており、それに関するトラブルシューティングを試みました。Southsqlite

トレースバック付きのエラー メッセージ

$ ./manage.py test --settings=settings.test -v2

Creating test database for alias 'default' (':memory:')...
Syncing...
Creating tables ...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table south_migrationhistory
Installing custom SQL ...
Installing indexes ...

Synced:
 > grappelli
 > django.contrib.admin
 > django.contrib.admindocs
 > django.contrib.auth
 > django.contrib.contenttypes
 > django.contrib.messages
 > django.contrib.sessions
 > django.contrib.sites
 > django.contrib.staticfiles
 > crispy_forms
 > floppyforms
 > south
 > subdomains
 > widget_tweaks

Not synced (use migrations):
 - apps.application
 - apps.app_app
 - apps.accounts
 - apps.rampup
 - apps.students
 - apps.automated_responses
(use ./manage.py migrate to migrate these)

======================================================================
ERROR: test_can_save_form_with_clean_passwords (apps.accounts.tests.test_admin.TestCreateUserForm)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/chaz/dev/projects/si/apps/accounts/tests/test_admin.py", line 17, in setUp
    self.user = SIDummyUserFactory.create()
  File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/factory/base.py", line 452, in create
    attrs = cls.attributes(create=True, extra=kwargs)
  File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/factory/base.py", line 316, in attributes
    force_sequence=force_sequence,
  File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/factory/containers.py", line 263, in build
    sequence = self.factory._generate_next_sequence()
  File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/factory/base.py", line 287, in _generate_next_sequence
    cls._next_sequence = cls._setup_next_sequence()
  File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/factory/django.py", line 71, in _setup_next_sequence
    ).order_by('-pk')[0]
  File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/django/db/models/query.py", line 231, in __getitem__
    return list(qs)[0]
  File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/django/db/models/query.py", line 108, in __len__
    self._result_cache.extend(self._iter)
  File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/django/db/models/query.py", line 1140, in iterator
    for row in self.query.get_compiler(self.db).results_iter():
  File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 775, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 840, in execute_sql
    cursor.execute(sql, params)
  File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 366, in execute
    six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2])
  File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 362, in execute
    return Database.Cursor.execute(self, query, params)
DatabaseError: no such table: accounts_siuser

関連する設定

INSTALLED_APPS

In [2]: settings.INSTALLED_APPS  
Out[2]:
('grappelli',  
 'django.contrib.admin',  
 'django.contrib.admindocs',  
 'django.contrib.auth',  
 'django.contrib.contenttypes',  
 'django.contrib.messages',  
 'django.contrib.sessions',  
 'django.contrib.sites',  
 'django.contrib.staticfiles',  
 'crispy_forms',  
 'floppyforms',  
 'south',  
 'subdomains',  
 'widget_tweaks',  
 'gunicorn',  
 'apps.application',  
 'apps.app_app',  
 'apps.automated_responses',  
 'apps.accounts',  
 'apps.rampup',  
 'apps.students',  
 'utils.context_processors',  
 'discover_runner')  

pip freeze --local

 Django==1.5.4  
 Pygments==1.6  
 South==0.7.6  
 argparse==1.2.1  
 bpython==0.12  
 coverage==3.6  
 dj-database-url==0.2.1  
 django-braces==1.2.2  
 django-crispy-forms==1.2.2  
 django-debug-toolbar==0.9.4  
 django-discover-runner==0.4  
 django-filepicker==0.1.4  
 django-floppyforms==1.1  
 django-grappelli==2.4.4  
 django-parsley==0.0.2a0  
 django-subdomains==2.0.1  
 django-templated-email==0.4.7  
 django-widget-tweaks==1.1.2  
 envoy==0.0.2  
 factory-boy==2.1.1  
 gunicorn==0.16.1  
 ipdb==0.7  
 ipython==0.13.2  
 psycopg2==2.4.5  
 pytz==2013b  
 requests==2.0.0  
 simplejson==3.3.1  
 six==1.4.1  
 stripe==1.7.7  
 zulip==0.2.1  

設定/test.py

""" Test settings and globals which allow us to write our tests locally."""
from .common import *

########
# APPS #
########
INSTALLED_APPS += (
    'discover_runner',
)

#################
# TEST SETTINGS #
#################
#TEST_RUNNER = 'django_pytest.test_runner.TestRunner'
TEST_RUNNER = "discover_runner.DiscoverRunner"
TEST_DISCOVER_TOP_LEVEL = PROJECT_ROOT
TEST_DISCOVER_PATTERN = "test_*"
SOUTH_TESTS_MIGRATE = False


###########################
# IN MEMORY TEST DATABASE #
###########################

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": ":memory:",
    },
}

問題を解決しなかった同様の SO の質問

これまでに試したこと

  • これが発生したときに変更されなかった別のブランチでテストを実行すると、 結果:まったく同じエラーとトラックバックが返されます
  • 仮想環境を吹き飛ばして新しい環境を開始
    結果: 変化なし
4

1 に答える 1