开发者

Django TestRunner Incorrect Query Counts, Corrupted Data?? General Mayhem

I've been having a very strange problem.

I have a test class that subclasses django.test.TestCase which has about 5 different tests in it. When I run my full test suite (using nose, and specifying sqlite as backend) there are a series of failures. When I go to debug the tests, running them individually, they pass fine.

In one of my tests I get the count of objects before adding an additional object. ex.

test_count = TestObject.objects.all().count()开发者_StackOverflow
# Add an entry to TestObject
self.assertEqual(test_count + 1, TestObject.objects.all().count()) # should pass

This was confusing that it would work fine when run individually but not when run with other tests. In pdb when I look at the variables, test_count is equal to 1, but TestObjects.objects.all().count() is equal to [] after the first line.

ipdb> test_count
1
ipdb> TestObject.objects.all()
[]
ipdb> TestObject.objects.all().count()
0

This takes place right on the second line after assigning value to test_count but before adding another object to TestObject

When my coworker runs our tests all of his pass fine.

Has anyone experienced things of this nature before? I have tried to change the variable names, I thought maybe there was a conflict somewhere. I am all out of ideas. Thank you for your help.


According to the SO post, you're seeing TestObject.objects.all().count() return two different values on successive calls.

That is basically impossible unless there's something else getting in there and doing stuff to your db.

Alternatively, does your subclass of TestCase correctly call super(MyTestCase, self).setUp() and other superclass methods to get the DB setup right?

Malcolm

posted from django-users

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜