﻿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
11064	TestCase Docs: Problematic import in Codesnippet	kanu@…	nobody	"There is a problem when importing models into your test.py as mentioned in http://docs.djangoproject.com/en/dev/topics/testing/#writing-unit-tests.

{{{
from myapp.models import Animal
}}}

If you register your signals in the models.py as suggested in the docs. They will be registered twice when testing and therefore will be called twice during test runs.
At least this isn't the demanded behavior at worst it throws a an error where no error is.
eg:

{{{
class Member(models.Model):
  user = models.ForeignKey(User, unique=True)
  ...

def create_user_profile(sender,instance,created,**kws):
  if create:
    m = Member(user = instance )
    m.save()

signals.post_save.connect(create_user_profile,sender=User)
}}}

The second time create_user_profile() is called it throws a '''IntegrityError: duplicate key value violates'''.

To fix this you can change the import in test.py to
{{{
from myproject.myapp.models import Animal
}}}
or 
{{{
from models import Animal 
}}}
the handler are registered only once and everything works fine when running tests."		closed	Documentation	1.0		wontfix	Test Signal IntegrityError		Unreviewed	0	0	0	0	0	0
