﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22280	"""Conflicting models in application"" RuntimeError for same model with different paths"	Daniel Hahler	nobody	"When I run tests using `manage.py test`, the test file `project/app/tests.py` is used/imported with `__name__ = ""project.project.app.test""`.

When using a relative import in tests.py then, the model appears to get registered as `project.project.app.model`.

After the database for the tests is being setup, I get the following error:

> RuntimeError: Conflicting 'model' models in application 'app': <class 'app.models.Model'> and <class 'project.project.app.models.Model'>.

It refers to the same Model, but with different class paths.

This is triggered by / caused when using an relative import from the tests.py file: `from .models import Model`.

I am running manage.py from the first ""project"" directory.

`sys.path` contains the directory `.../project/project` and not the directory where `project.project.app` would be rooted.

With Django 1.6 the `__name__` of tests.py during the import is the same, but there's no error, since there is no apploader that verifies uniqueness using the labels/names.

I could not reproduce it with a simple new project/app in Django 1.7.

{{{
ERROR: project.project.app.tests (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: project.project.app.tests
Traceback (most recent call last):
  File ""/usr/lib/python2.7/unittest/loader.py"", line 254, in _find_tests
    module = self._get_module_from_name(name)
  File ""/usr/lib/python2.7/unittest/loader.py"", line 232, in _get_module_from_name
    __import__(name)
  File ""…/project/app/tests.py"", line 23, in <module>
    from .views import HomePageView
  File ""…/project/app/views.py"", line 6, in <module>
    from .models import Movie, Collection
  File ""…/project/app/models.py"", line 51, in <module>
    class Person(models.Model):
  File ""…/django-master/django/db/models/base.py"", line 299, in __new__
    new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
  File ""…/django-master/django/apps/registry.py"", line 201, in register_model
    (model_name, app_label, app_models[model_name], model))
RuntimeError: Conflicting 'person' models in application 'app': <class 'app.models.Person'> and <class 'project.project.app.models.Person'>.

}}}
"	Bug	closed	Testing framework	dev	Normal	worksforme		cmawebsite@…	Accepted	0	0	0	0	0	0
