I recently upgraded one of my projects to 1.6 and was surprised to find that some of my tests were failing. I filed a ticket [1], and the subsequent discussion with Aymeric makes me think that there is a tricky issue here, worth discussing.
The basic problem is that when using TestCase you can end up with test failures for correct, non-transactional code, due to the fact that TestCase is wrapping your test in a transaction. Some examples: - If your non-transactional code catches a database error and continues (which is perfectly fine), your TestCase test for it will produce a TransactionManagementError. - Similarly, if your TestCase does an assertRaises() for a DatabaseError, and then hits the database again after that, you will get an error. - Aymeric mentions: "The problem is not limited to database errors, it is known to happen if a post-save signal handler raises an exception." The straightforward solution is to use TransactionTestCase instead. Currently, though, the documentation just advises you to use TransactionTestCase "when testing transactional behavior". These examples show that that advice is too limited. We should catalog the ways in which TestCase behavior can diverge from TransactionTestCase and update the documentation accordingly. More broadly, though, this makes me wonder whether it's a good idea for the documentation to present TestCase as the de facto default base class for tests. On the one hand we have that old standby, TransactionTestCase (formerly known as TestCase), which slowly but safely plows through its tests, dutifully truncating tables. On the other hand we have TestCase, its younger usurper, which is much faster but which is also less general, failing in ways that could confuse new users who may not know anything about transaction management (and who are probably also the least likely to need the faster tests). Are we leading them into a premature optimization? Cheers, Kevin [1] https://code.djangoproject.com/ticket/21540 -- You received this message because you are subscribed to the Google Groups "Django developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/5471ca9a-fa4f-4c88-88b7-cbd9577d215f%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.