I try to speedup my tests by putting test data from test case setUp()
to setUpClass()/teardownClass
class method, so it does not recreate same select only fixture for every test in test case.
@classmethod
def setUpClass(cls):
plant.StuffFactory() #plant stuff with FactoryBoy
transaction.commit()
@classmethod
def tearDownClass(cls):
session.query(models.Stuff).delete() # delete planted stuff
transaction.commit()
But i don't like deleting stuff with session.delete on my own, because i use many models and don't want track what i planted. I want something like
@classmethod
def tearDownClass(cls):
session.clear() #delete all
transaction.commit()
But session.close()
or session.remove()
will not affect committed data.
So i seek some way to "cancel" setUpClass
transaction.commit()
like i don't plant anything.
I try nested transactions and savepoints but again they works only if data not committed yet.
Any pointers?