In my tests I do not only test for the perfect case, but especially for edge cases and error conditions. So I wanted to ensure some uniqueness constraints work.
While my test and test fixtures are pretty complicated I was able to track the problem down to the following example, which does not use any custom models. To reproduce the behaviour just save the code into tests.py and run the django test runner.
from django.contrib.auth.models import User
from django.db import IntegrityError
from django.test import TransactionTestCase
class TransProblemTest(TransactionTestCase):
def test_uniqueness1(self):
User.objects.create_user(username='user1', email='[email protected]', password='secret')
self.assertRaises(IntegrityError, lambda :
User.objects.create_user(username='user1', email='[email protected]', password='secret'))
def test_uniqueness2(self):
User.objects.create_user(username='user1', email='[email protected]', password='secret')
self.assertRaises(IntegrityError, lambda :
User.objects.create_user(username='user1', email='[email protected]', password='secret'))
A test class with a single test method works, but fails with two identical method implementations. The first test throwing exception breaks the Django testing environment and makes all the following tests fail.
I am using Django 1.1 with Ubuntu 10.04, Postgres 8.4 and psycopg2.
Does the problem still exist in Django 1.2?
Is it a known bug or am I missing something?