On Tue, Dec 13, 2011 at 8:33 AM, Acruax <acr...@gmail.com> wrote: > Hi, > I have a problem with model testing. My test fails with error: > IntegrityError: duplicate key value violates unique constraint > "catalog_name_key" > DETAIL: Key (name)=(test_catalog1) already exists. > > I have unique=True on name field. > > class CatalogTestCase(unittest.TestCase): > def setUp(self): > self.catalog1 = Catalog.objects.create(name="test_catalog1", > title_ru="Test Catalog1") >
For tests that use the database, you need to extend from django.test.TestCase, not unittest.TestCase. Django's custom TestCase will ensure that the database is reset to its initial state between tests (see https://docs.djangoproject.com/en/1.3/topics/testing/#testcase). The need for using Django's custom TestCase is unfortunately not currently properly noted in the docs, and there is a ticket open on that ( https://code.djangoproject.com/ticket/17312). Karen -- http://tracey.org/kmt/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.