最近Django 1.8.4にアップグレードしたDjangoアプリケーションがあります。テストランナーが200回以上の統合テストと単体テストを実行するために、ノーズ1.3.7とdjango-nose 1.4.1を使用しています。ジャンゴと鼻の両方をアップグレードするので、私は私のテストの12は、この同じエラーで失敗することを発見しています:Django 1.8とnose:競合モデルですか?
======================================================================
ERROR: Failure: RuntimeError (Conflicting 'c' models in application 'nose': <class 'account.tests.form_tests.TestAddress'> and <class 'nose.util.C'>.)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/me/venv/myproj/lib/python2.7/site-packages/nose/loader.py", line 523, in makeTest
return self._makeTest(obj, parent)
File "/Users/me/venv/myproj/lib/python2.7/site-packages/nose/loader.py", line 568, in _makeTest
obj = transplant_class(obj, parent.__name__)
File "/Users/me/venv/myproj/lib/python2.7/site-packages/nose/util.py", line 644, in transplant_class
class C(cls):
File "/Users/me/venv/myproj/lib/python2.7/site-packages/django/db/models/base.py", line 311, in __new__
new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
File "/Users/me/venv/myproj/lib/python2.7/site-packages/django/apps/registry.py", line 223, in register_model
(model_name, app_label, app_models[model_name], model))
RuntimeError: Conflicting 'c' models in application 'nose': <class 'account.tests.form_tests.TestAddress'> and <class 'nose.util.C'>.
何好奇心が強いのはform_tests.pyモジュールでも、実際に内部クラスですTestAddressを参照していないということです私の "プロファイル" モデル:
# myprof/profile/models.py
class TestAddress(models.Model):
user = models.OneToOneField(User, primary_key=True, unique=True)
address_line_1 = models.CharField(max_length=30)
address_line_2 = models.CharField(max_length=30, null=True, blank=True)
city = models.CharField(max_length=30)
region = models.CharField(max_length=30, null=True, blank=True)
postal_code = models.CharField(max_length=10, null=True, blank=True)
country = models.ForeignKey('Country')
class Meta:
db_table = 'test_address'
def __unicode__(self):
return u'%s' % (self.user.username)
私のテストはTestAddressクラスのインスタンスを生成する必要があり、私はfactory_boyを使う(V 2.5.2。)工場:私はブレークポイントを設定
# utils/factories.py
from profile.models import TestAddress
class UserFactory(factory.django.DjangoModelFactory):
class Meta:
model = User
username = 'testuser'
class TestAddressFactory(factory.django.DjangoModelFactory):
class Meta:
model = TestAddress
user = factory.SubFactory('utils.factories.UserFactory')
address_line_1 = '123 Main St.'
address_line_2 = 'Apt. A'
city = 'AnyCity'
region = 'AnyRegion'
postal_code = '12345'
country = factory.SubFactory('utils.factories.CountryFactory')
nose loader.pyモジュールで、 "profile.models"に "TestAddress"が表示されていることが確認されました。しかし、 "parent .__ name__"という変数があり、 "account.tests.model_tests"に設定されています。私が質問のカップルを持っている:
1. Why is this occurring?
2. Is there a way I can fix it?
3. Is there some way I can get nose to tell me which tests are resulting in these runtime errors so that I can at least disable them if I can't fix the problem?
私は「--verbosity = 2」に設定したが が失敗テストの名前が表示されないこと。私は鼻の文書を見て、何も見なかった。最悪の場合私は、すべてのテストを個別に呼び出すためのスクリプトを書くことができますし、実行する前にテスト名をエコーすることもできますが、それは非常に面倒で時間がかかるようです。
ありがとうございました。