Melange's DjangoTestCase inherits from TransactionTestCase instead of TestCase.
Melange's DjangoTestCase inherits from TransactionTestCase instead of TestCase.

It may sound look at first, as TransactionTestCase looks like something that is more specific than TestCase. It is not true. The actual class hierarchy is as follows:

unittest.TestCase
|
SimpleTestCase (since Django 1.4)
|
TransactionTestCase
|
TestCase

The last two classes are almost identical, according to documentation, except for how they handle DB transactions. The latter one monkey patches transaction management at the end of each test. It is supposed to speed up the process of resetting the database after each test. Anyway, from Melange's perspective it does not really matter, as it does not use any real database backends provided by Django.

Why do this change happens?
TestCase class performs some initialization that cannot be handled by the dummy DB backend. Actual tests do not fail only because _pre_setup function is overriden and does not call super(). It is fine now, as apparently no important work is done in parent classes. What if something substantial was moved to _pre_setup of one of the base classes? The code would have to be copied to Melange's _pre_setup function.

This is what actually happens in one of the newer versions of Django. The most important part from Melange's perspective is that client member is set. As of Django 1.2 it is done in __call__ menthod of TransactionTestCase. After that, it is moved to _pre_setup.

In my humble opinion, the fact that client is initialized only in TransactionTestCase is wrong after all. This class should support test cases which are supposed to take advantage of databases and/or transactions. Client is an object that can accept and dispatch actual HTTP requests. Fortunately, Django team has come to that conclusion as well and client's initialization has been moved up to SimpleTestCase in the upcoming Django 1.6 release.

As the abovementioned release has not been rolled out yet (it is still in beta), TransactionTestCase works best for Melange, as there is no difference at all and it does not cause the code to fail.

rhyolight/nupic.son,rhyolight/nupic.son,rhyolight/nupic.son