Getting rid of empty models.py in django testsuite

2019-06-16 03:18发布

问题:

I have two pure service apps, that act as servant to my core models. Hence, they do not have any own models.

While the testsuite for the first service runs fine, the second throws the following error:

django.core.exceptions.ImproperlyConfigured: 
App with label location is missing a models.py module. 

If I add an empty models.py, the suite runs fine.

I can't spot a difference in terms of architecture / structure between the apps. But I want to get rid of the empty, unneeded models.py.

How would I do that?

回答1:

Update: What you ask is now possible. With Django 1.7 you no longer need a models.py file. -release notes

Previously: Django testing requires every app to have a models.py file. It's okay to leave it empty (or with a helpful comment!). Ticket discussion on the matter of apps without models. Direct from the code (added in 1.4/still in 1.5):

the test runner won't currently load a test module with no models.py file



回答2:

As far as I know, it is necessary to include a 'models.py' module on every Django application to make it run properly