1
votes

What is causing this error in my django app only when I run unit tests? Why does it think nose.util.C is a model?

RuntimeError: Model class nose.util.C doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded.

1
I can't comment, but I added my answer at stackoverflow.com/a/56723920/1305080 because it sounded like that wasn't actually solved and this and that might be the same issue as mine. - jbothma

1 Answers

4
votes

You may have a model that has Test in its name. Nose is wrapping the class and confusing Django.

jwhitlock on github explains,

My current guess is that nose is detecting a model class that it thinks it should run tests - maybe because it is named Test, or TestFoo, or FooTest, and it wrapping it in transplant_class, which is freaking out Django's model loader. If this is the case, it may work if you rename the class, or don't do Python path manipulations, or add a __test__= False class declaration.

The other alternative is to use @nottest from nose.tools to decorate the class:

from nose.tools import nottest

@nottest
class Testacean(Model):
    ...