On Fri, Aug 27, 2010 at 1:43 AM, Elf_Sternberg <elf.sternb...@gmail.com> wrote:
> Is anyone seeing this?  I have this function at the top of my
> unittest:
>
> def create_user(name):
>    username = name.replace(' ', '').lower()
>    return User.objects.create_user(username, username + '@a.com',
> 'password')
>
> And then (this is ultimately the code I derived to examine this
> behavior):
>
> class StartupTest(TestCase):
>    def setUp(self):
>        users = [create_user(name) for name in ["Fred", "Barney",
> "Pebbles"]]
>
>    def test1(self):
>        print User.objects.all()
>
>    def test2(self):
>        print User.objects.all()
>
> The output was:
> [<User: fred>, <User: barney>, <User: pebbles>]
> [<User: >, <User: >, <User: >]
>
> Where did the usernames go in the second test?  My understanding of
> the documentation is that the test driver is supposed to update the
> database with every new test.  It doesn't seem to be working with
> Users, and I'm not sure why.

Are you using a django.test.TestCase or unittest.TestCase?

If you're using unittest.TestCase, then the 'units' won't be as
isolated as you perhaps think. The database persists between database
runs, so objects created in one test will still exist when the second
executes.

If you use django.test.TestCase, Django will return the database to a
pristine state at the start of each test. Alternatively, you could use
a tearDown() method in your testcase to clean up the objects that you
create.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.

Reply via email to