Lately, I found out that Django’s TransactionTestCase leaves test data in database after the test case is executed. It’s not until the next execution of presetup method of a TransactionTestCase instance that the database is flushed. This is troublesome when tests are run with Django Nose’s test runner with REUSE_DB =1.
An easy fix to this is to customize the TransactionTestCase so that it deletes the test data on exit. I wrote a simple wrapper around Django’s TransactionTestCase and extend it to write other transaction test cases.
from django.test import TransactionTestCase
from django.db import connections, DEFAULTDBALIAS
if getattr(cls, ‘multidb’, False):
databases = connections
databases = [DEFAULTDBALIAS]
for db in databases: