samedi 28 mars 2015

Retaining items created during setup of a python test

I'm writing a test suite for a custom manager in Django, and want to test a large number of items.


Essentially, it requires creating several thousand items, due to a combinatorial explosion.


What I need is a way to create a lot of django objects in the database and have them retained through the whole test class instead of recreating them.


I have the following code:



class CustomConceptQuerySetTest(TestCase):
def setUp(self):
pass #make lots and lots of items.

def test_is_public(self):
pass # check if returned items in the object.public() queryset are actually "public"
def test_is_editable(self):
pass # check if returned items in the object.viewable() queryset are actually "viewable" only to certain users.


Unfortunately, setUp is called before each test, but the content is not changed during tests, only read, and is the same each time.


Is there a way in Django to keep the database, or prevent rollbacks or destruction within a test Class?


Aucun commentaire:

Enregistrer un commentaire