class MyClassTest(TestCase):
def setUp(self):
Someclass.objects.create()
def test_first_test(self):
# Here, Someclass.objects.all()[0].pk -> returns 1
def test_second_test(self):
# Here, Someclass.objects.all()[0].pk -> returns 2 !!! (bad !)
With SetUp()
method, the data is supposed to be cleared and recreated between each test.
So, why ids increment from one test to another? It's not obvious to me.
This way I can't make tests based on ids (since they depends on other tests).
That's why I'd like to get always 1
as result.
Note that I have no problem with the data itself, old data is well cleared from one test to another one. The problem is just about ids.
I read here django object ids increment between unit tests that the problem is related to the database, not to Django, but is there any trick in Django to change that?