1

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.

rrauenza
  • 6,285
  • 4
  • 32
  • 57
  • I can't comment, but I added my answer at https://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 Jun 23 '19 at 12:39

1 Answers1

6

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):
    ...
rrauenza
  • 6,285
  • 4
  • 32
  • 57