I have a Django application I recently upgraded to Django 1.8.4. I’m using nose 1.3.7 and django-nose 1.4.1 for my test runner to run over 200 integration and unit tests. Since upgrading both Django and nose, I’m finding that 12 of my tests fail with this same error:
====================================================================== 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'>.
What’s curious is that the form_tests.py module doesn’t even reference TestAddress which is actually a class inside my “profiles” model:
# 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)
When my tests need to generate an instance of the TestAddress class, I use a factory_boy (v. 2.5.2) factory:
# 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')
I set breakpoints in the nose loader.py module and confirmed that loader sees “TestAddress” in “profile.models”. However, there is a “parent.__name__” variable there which is set to “account.tests.model_tests”. I have a couple of questions:
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?
I set “–verbosity=2” but that
doesn’t display the names of failing tests. I looked through the nose docs and didn’t see anything. Worst case I can write a script to call every test individually and echo the test name before running it but that seems very ugly and time-consuming.
Reset to default
Introducing: Trending sort
You can now choose to sort by Trending, which boosts votes that have happened recently, helping to surface more up-to-date answers.
Trending is based off of the highest score sort and falls back to it if no posts are trending.
I ran into the same issue while porting my Django project from 1.6 to 1.8 and updating django-nose to 1.4.3.
It appears that with the new
DiscoverRunner used in 1.7 onwards, django-nose attempts to run all classes beginning with
Test* as Test Cases, which leads to them being adapted into django-nose’s django app before they are encountered in test modules.
I managed to resolve this issue by renaming them to avoid this naming scheme, to things like
I just encountered this and solved it with the @nottest decorator.
Technically, it’s for functions according to the docs, but decorating classes with it also works:
from nose.tools import nottest @nottest class TestAddressFactory(...): ...
All the decorator does is add
__test__ with the value
True to the object it is decorating.
def nottest(func): """Decorator to mark a function or method as *not* a test """ func.__test__ = False return func