Hi I have imported my model classes in models/__init__.py (as described in docs <https://docs.djangoproject.com/en/dev/ref/applications/#how-applications-are-loaded> ):
You must define or import all models in your application’s models.py or > models/__init__.py. Otherwise, the application registry may not be fully > populated at this point, which could cause the ORM to malfunction. However after doing this, running tests with ./manage.py test -k causes the unittest loader to fail with: ERROR: myapp.api.models (unittest.loader._FailedTest) ---------------------------------------------------------------------- ImportError: Failed to import test module: myapp.api.models Traceback (most recent call last): File "/usr/lib/python3.6/unittest/loader.py", line 462, in _find_test_path package = self._get_module_from_name(name) File "/usr/lib/python3.6/unittest/loader.py", line 369, in _get_module_from_name __import__(name) File "/myapp/api/models/__init__.py", line 5, in <module> from .api_key import ApiKey File "/myapp/api/models/api_key.py", line 17, in <module> class ApiKey(models.Model): File "/-Z_V0-nQl/lib/python3.6/site-packages/django/db/models/base.py", line 111, in __new__ "INSTALLED_APPS." % (module, name) RuntimeError: Model class myapp.api.models.api_key.ApiKey doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS. The workaround is to run: ./manage.py test -k api.tests (then the test loader doesn't try to load __init__.py) This issue is discussed on SO <https://stackoverflow.com/questions/21069880/running-django-tutorial-tests-fail-no-module-named-polls-tests> - I wondered if it could be a bug? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4f622eb1-d3fc-4fe9-a6fa-e097f7257130%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.