Problems using User model in django unit tests

Posted by theycallmemorty on Stack Overflow See other posts from Stack Overflow or by theycallmemorty
Published on 2010-05-15T14:32:54Z Indexed on 2010/05/15 14:44 UTC
Read the original article Hit count: 246

I have the following django test case that is giving me errors:

class MyTesting(unittest.TestCase):
    def setUp(self):
        self.u1 = User.objects.create(username='user1')
        self.up1 = UserProfile.objects.create(user=self.u1)

    def testA(self):
        ...

    def testB(self):
        ...

When I run my tests, testA will pass sucessfully but before testB starts, I get the following error:

IntegrityError: column username is not unique

It's clear that it is trying to create self.u1 before each test case and finding that it already exists in the Database. How do I get it to properly clean up after each test case so that subsequent cases run correctly?

© Stack Overflow or respective owner

Related posts about django

Related posts about django-testing