> What is the proper way to "reset" or "rollback" the connection in a > test case after an IntegrityError has been raised? This only seems to > be an issue with PostgresSQL; in sqlite the "current transaction is > aborted, commands ignored" doesn't seem to come up. > > > What version of Django are you using? It sounds like you may be using a > 1.1 (alpha/beta/trunk) level, which means if you want to be able to use > transaction methods such as commit or rollback and see their effects, > you will need to use a django.test.TransactionTestCase instead of a > django.test.TestCase. See: > > http://docs.djangoproject.com/en/dev/topics/testing/#testcase > > Karen
I am indeed using the latest trunk (R10651). I'm actually not particularly interested in testing commit or rollback; though thanks for the pointer, that helps for the future. I'm really just interested in testing cases which raise IntegrityError's. It seems that any time an IntegrityError is produced, the postgres connection becomes stuck. Subsequently, all attempts to access the database result in the error: InternalError: current transaction is aborted, commands ignored until end of transaction block The following is a minimal test case. The test passes with SQLite, but fails with postgressql_psycopg2 with the aforementioned error. If this code should work properly, I'll file a ticket. class SomeModel(models.Model): name = models.CharField(max_length=50, unique=True) class TestIntegrity(TestCase): def test_integrity_error(self): # First try should succeed self.assertTrue(self.make_spam()) # Should violate the unique constraint self.assertRaises(IntegrityError, self.make_spam) # Is the db connection still functional? self.assertEquals(len(SomeModel.objects.all()), 1) def make_spam(self): SomeModel.objects.create(name='spam') return True Thanks! Charlie --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---