Test runner wants to run models package?!

39 views
Skip to first unread message

Torsten Bronger

unread,
Apr 26, 2016, 6:04:56 PM4/26/16
to django...@googlegroups.com
Hallöchen!

With Django 1.9.5 (rest are original Ubuntu 16.04 packages) and
Python 3.5.1, "manage.py test myapp" tries to run the *models*
package of myapp as a test module:

user@localhost:~/src/myproject/myproject$ ./manage.py test myapp --pattern=invalid_pattern
Creating test database for alias 'default'...
Destroying old test database for alias 'default'...
E
======================================================================
ERROR: myproject.myapp.models (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: myproject.myapp.models
Traceback (most recent call last):
File "/usr/lib/python3.5/unittest/loader.py", line 462, in _find_test_path
package = self._get_module_from_name(name)
File "/usr/lib/python3.5/unittest/loader.py", line 369, in _get_module_from_name
__import__(name)
File "/home/user/src/myproject/myproject/myapp/models/__init__.py", line 26, in <module>
from .physical_processes import *
File "/home/user/src/myproject/myproject/myapp/models/physical_processes.py", line 66, in <module>
class Substrate(PhysicalProcess):
File "/usr/local/lib/python3.5/dist-packages/django/db/models/base.py", line 102, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class myproject.myapp.models.physical_processes.Substrate doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.


----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)
Destroying test database for alias 'default'...



I chose "invalid_pattern" to limit it to the models package.
Without "--pattern", all *real* tests are run, too. Using Python2,
everything is fine. Does anybody have an idea what's going on here?

Tschö,
Torsten.

--
Torsten Bronger Jabber ID: torsten...@jabber.rwth-aachen.de

Tim Graham

unread,
Apr 26, 2016, 6:53:44 PM4/26/16
to Django users
Could you try Python 3.4.x? I ran into some issues with Django's own test suite [0] due to some import changes in Python 3.5 [1].

[0] https://code.djangoproject.com/ticket/23763#comment:11
[1] http://bugs.python.org/issue7559

Torsten Bronger

unread,
Apr 27, 2016, 12:46:45 PM4/27/16
to django...@googlegroups.com
Hallöchen!

Tim Graham writes:

> Could you try Python 3.4.x?

The problem does not exist with Python 3.4.3. (Ubuntu 14.04)

> I ran into some issues with Django's own test suite [0] due to
> some import changes in Python 3.5 [1].

If I look at Python 3.5's release notes, the following is
suspicious:

Found packages are now checked for load_tests regardless of
whether their path matches pattern, because it is impossible for
a package name to match the default pattern.

I understand this this way: The pattern still works for .py files
but not for packages (__init__.py files). And since my models'
__init__.py says

from .physical_processes import *

and the app is not yet set up, this breaks.


Question is: Is is bad style to have a models *package* which
collects alls models in its __init__.py, or has Django to be adapted
to Python's new behaviour?
Reply all
Reply to author
Forward
0 new messages