I'm helping my group upgrade their application from python 2 to 3, and am running into errors with the unit tests. When I run the tests with:
python3 manage.py test groupapp --settings=settings.deploy_dev
I get the errors below. But if I run with:
python3 manage.py test groupapp.tests --settings=settings.deploy_dev
the errors do not occur. Its worth noting that these errors occur even after I deleted all our tests from the tests folder, and as far as I can tell they aren't connected to an actual test case.
I don't understand the difference between these two calls in python 3. In python 2 if I run the two calls I get the same result (no test failures).
groupapp_v2.groupapp.admin (unittest.loader._FailedTest) ... ERROR
groupapp_v2.groupapp.models (unittest.loader._FailedTest) ... ERROR
======================================================================
ERROR: groupapp_v2.groupapp.admin (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: groupapp_v2.groupapp.admin
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 462, in _find_test_path
package = self._get_module_from_name(name)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 369, in _get_module_from_name
__import__(name)
File "/Users/matthew/bitbucket/consortium-website/groupapp_v2/groupapp/admin/__init__.py", line 73, in <module>
admin.site.register(Grid, GridAdmin)
File "/Users/matthew/virtualenv/groupapp-python3.6/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 110, in register
raise AlreadyRegistered('The model %s is already registered' % model.__name__)
django.contrib.admin.sites.AlreadyRegistered: The model Grid is already registered
======================================================================
ERROR: groupapp_v2.groupapp.models (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: groupapp_v2.groupapp.models
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 462, in _find_test_path
package = self._get_module_from_name(name)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 369, in _get_module_from_name
__import__(name)
File "/Users/matthew/bitbucket/consortium-website/groupapp_v2/groupapp/models/__init__.py", line 7, in <module>
from .deployable import *
File "/Users/matthew/bitbucket/consortium-website/groupapp_v2/groupapp/models/deployable.py", line 22, in <module>
class Keyword_LibraryM2M(Model):
File "/Users/matthew/virtualenv/groupapp-python3.6/lib/python3.6/site-packages/django/db/models/base.py", line 118, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class groupapp_v2.groupapp.models.deployable.Keyword_LibraryM2M doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.```